Skip to content

Commit 4df06bc

Browse files
authored
Snap build for the micro-ROS-Agent (#43)
* Add snap packaging * First approach for snap packaging * Working state * Fixes * Simplify snapcraft.yaml * Fix snapcraft build * Fix daemon * Fix compilation due to external micro_ros_msgs * CMakeLists cleanup
1 parent e9330bf commit 4df06bc

File tree

6 files changed

+273
-4
lines changed

6 files changed

+273
-4
lines changed

micro_ros_agent/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ if(UROSAGENT_GENERATE_PROFILE)
122122
set(_XML_DEFAULT_READ_BIN "${_OUTPUT_PATH}/bin/Xml_read_default_profiles.py")
123123
normalize_path(_XML_DEFAULT_READ_BIN "${_XML_DEFAULT_READ_BIN}")
124124

125-
set(_PYTHON_PKG_TOOL ${PROJECT_NAME})
125+
set(_PYTHON_PKG_TOOL utils)
126126

127127
set(_RESOURCE_DIR "${_OUTPUT_PATH}/resource")
128128
normalize_path(_RESOURCE_DIR "${_RESOURCE_DIR}")
@@ -198,7 +198,7 @@ from ${_PYTHON_PKG_TOOL} import *
198198
endforeach()
199199

200200
execute_process(
201-
COMMAND
201+
COMMAND
202202
"${PYTHON_EXECUTABLE}" "${_XML_DEFAULT_READ_BIN}" "--default-xml-path" "${_RESOURCE_DIR}"
203203
OUTPUT_VARIABLE
204204
_XmlDoc
@@ -207,7 +207,7 @@ from ${_PYTHON_PKG_TOOL} import *
207207
)
208208

209209
if(NOT _result EQUAL 0)
210-
message(FATAL_ERROR "Error in typesuppor generation")
210+
message(FATAL_ERROR "Error in typesupport generation")
211211
endif()
212212

213213
foreach(package ${_packages})
@@ -241,7 +241,7 @@ from ${_PYTHON_PKG_TOOL} import *
241241
)
242242

243243
if(NOT _result EQUAL 0)
244-
message(FATAL_ERROR "Error in typesuppor generation")
244+
message(FATAL_ERROR "Error in typesupport generation")
245245
endif()
246246

247247
set(_XmlDoc "${_XmlDoc}${_XmlGen}")
File renamed without changes.

snap/hooks/configure

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/bin/sh -e
2+
3+
# Confirm that the transport is valid
4+
transport="$(snapctl get transport)"
5+
case "$transport" in
6+
udp4) ;;
7+
udp6) ;;
8+
tcp4) ;;
9+
tcp6) ;;
10+
serial) ;;
11+
pseudoterminal) ;;
12+
*)
13+
echo "'$transport' is not a supported transport" >&2
14+
return 1
15+
;;
16+
esac
17+
18+
# Confirm that the middleware is valid
19+
middleware="$(snapctl get middleware)"
20+
case "$middleware" in
21+
dds) ;;
22+
rtps) ;;
23+
ced) ;;
24+
*)
25+
echo "'$middleware' is not a supported middleware" >&2
26+
return 1
27+
;;
28+
esac
29+
30+
if [ "$transport" = "serial" ] || [ "$transport" = "pseudoterminal" ]; then
31+
# A serial transport if being used, which requires a valid baud rate
32+
# as well as a valid device
33+
baudrate="$(snapctl get baudrate)"
34+
if ! expr "$baudrate" : '^[0-9]\+$' > /dev/null; then
35+
echo "'$baudrate' is not a valid baud rate" >&2
36+
return 1
37+
fi
38+
39+
device="$(snapctl get device)"
40+
if [ -z "$device" ]; then
41+
echo "Device must be specified" >&2
42+
return 1
43+
fi
44+
else
45+
port="$(snapctl get port)"
46+
if ! expr "$port" : '^[0-9]\+$' > /dev/null; then
47+
echo "'$port' is not a valid port" >&2
48+
return 1
49+
fi
50+
fi
51+
52+
# Confirm that discovery is a boolean
53+
discovery="$(snapctl get discovery)"
54+
case "$discovery" in
55+
true)
56+
# Confirm that discovery port is valid
57+
port="$(snapctl get discovery-port)"
58+
if ! expr "$port" : '^[0-9]\+$' > /dev/null; then
59+
echo "'$port' is not a valid discovery port" >&2
60+
return 1
61+
fi
62+
;;
63+
false) ;;
64+
*)
65+
echo "'$discovery' is not a valid boolean for discovery" >&2
66+
return 1
67+
;;
68+
esac
69+
70+
# Confirm that the verbosity is valid
71+
verbosity="$(snapctl get verbosity)"
72+
if ! expr "$verbosity" : '^[0-6]$' > /dev/null; then
73+
echo "'$verbosity' is not a valid verbosity" >&2
74+
return 1
75+
fi
76+
77+
# Confirm that p2p port is valid (assuming it's set)
78+
p2p_port="$(snapctl get p2p-port)"
79+
if [ -n "$p2p_port" ]; then
80+
port="$(snapctl get p2p-port)"
81+
if ! expr "$port" : '^[0-9]\+$' > /dev/null; then
82+
echo "'$port' is not a valid p2p port" >&2
83+
return 1
84+
fi
85+
fi
86+
87+
# Confirm that daemon is a boolean, and enable the service if true
88+
daemon="$(snapctl get daemon)"
89+
case "$daemon" in
90+
true)
91+
snapctl start --enable "$SNAP_INSTANCE_NAME.daemon"
92+
93+
# In case it was alraedy started and the configuration changed,
94+
# restart the service
95+
snapctl restart "$SNAP_INSTANCE_NAME.daemon"
96+
;;
97+
false)
98+
snapctl stop --disable "$SNAP_INSTANCE_NAME.daemon"
99+
;;
100+
*)
101+
echo "'$daemon' is not a valid boolean for daemon" >&2
102+
return 1
103+
;;
104+
esac

snap/hooks/install

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh -e
2+
3+
# Set default configuration values
4+
snapctl set transport=udp4
5+
snapctl set middleware=dds
6+
snapctl set verbosity=4
7+
snapctl set discovery=false
8+
snapctl set discovery-port=7400
9+
snapctl set p2p-port! # unset
10+
11+
# Network-specific things
12+
snapctl set port=8888
13+
14+
# Serial-specific things
15+
snapctl set baudrate=115200
16+
snapctl set device! # unset
17+
18+
# By default the daemon is disabled
19+
snapctl set daemon=false

snap/local/micro-ros-agent-daemon

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh -e
2+
3+
set -- --middleware "$(snapctl get middleware)" "$@"
4+
set -- --verbose "$(snapctl get verbosity)" "$@"
5+
6+
transport="$(snapctl get transport)"
7+
if [ "$transport" = "serial" ] || [ "$transport" = "pseudoterminal" ]; then
8+
set -- --dev "$(snapctl get device)" "$@"
9+
else
10+
set -- --port "$(snapctl get port)" "$@"
11+
fi
12+
13+
if [ "$(snapctl get discovery)" = "true" ]; then
14+
set -- --discovery "$@"
15+
16+
discovery_port="$(snapctl get discovery-port)"
17+
if [ -n "$discovery_port" ]; then
18+
set -- --disport "$discovery_port" "$@"
19+
fi
20+
fi
21+
22+
p2p_port="$(snapctl get p2p-port)"
23+
if [ -n "$p2p_port" ]; then
24+
set -- --p2p "$p2p_port" "$@"
25+
fi
26+
27+
exec "$SNAP/lib/micro_ros_agent/micro_ros_agent" "$transport" "$@"

snap/snapcraft.yaml

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: micro-ros-agent
2+
base: core20
3+
version: git
4+
summary: Bridge between Micro ROS client applications and ROS 2
5+
description: |
6+
Micro-ROS, whose default implementation is based on eProsima's
7+
Micro XRCE-DDS middleware, is composed of client applications
8+
which interact with the ROS 2 world by means of an Agent.
9+
This agent keeps tracks of the entities created by means of
10+
requests performed on the microcontroller side, and uses them
11+
to communicate with the ROS 2 dataspace.
12+
13+
Being an extension of the Micro XRCE-DDS Agent, the micro-ROS
14+
agent supports being run by the user like this:
15+
16+
$ micro-ros-agent --help
17+
18+
In addition, the Agent supports running as a service that can be
19+
enabled with:
20+
21+
$ snap set micro-ros-agent daemon=true
22+
23+
If the service is enabled, by default it uses the `udp4` transport on
24+
port 8888. The following parameters can be changed (these are
25+
specific to the service, the `micro-ros-agent` command simply
26+
takes command-line arguments, but the capabilities are the same):
27+
28+
* `transport`. Supported transports are `udp4`, `udp6`, `tcp4`,
29+
`tcp6`, `serial`, and `pseudoterminal`. Default is `udp4`. Change
30+
with:
31+
32+
$ snap set micro-ros-agent transport="new transport"
33+
34+
* `middleware`. Supported kinds of middleware are `ced`, `rtps`, and
35+
`dds`. Default is `dds`. Change with:
36+
37+
$ snap set micro-ros-agent middleware="new middleware"
38+
39+
* `verbosity`. Supported verbosity levels are 0-6, defaulting to 4.
40+
Change with:
41+
42+
$ snap set micro-ros-agent verbosity="selected verbosity"
43+
44+
* `discovery`. Enable or disable the discovery server. Defaults to
45+
"false". Change with:
46+
47+
$ snap set micro-ros-agent discovery="true or false"
48+
49+
* `discovery-port`. Port on which the discovery server (see above)
50+
listens. Defaults to 7400. Change with:
51+
52+
$ snap set micro-ros-agent discovery-port="selected port"
53+
54+
* `p2p-port`. Port to use for the P2P profile. Change with:
55+
56+
$ snap set micro-ros-agent p2p-port="selected port"
57+
58+
* `port`. Port on which the agent listens. Only applicable to one of
59+
the UDP or TCP transports (see above). Defaults to 8888. Change with:
60+
61+
$ snap set micro-ros-agent port="selected port"
62+
63+
* `baudrate`. Baud rate to use when accessing serial ports. Only
64+
applicable when using the `serial` or `pseudoterminal` transport.
65+
Defaults to 115200. Change with:
66+
67+
$ snap set micro-ros-agent baudrate="baud rate"
68+
69+
* `device`. The serial device to use. Only applicable when using the
70+
`serial` or `pseudoterminal` transport. Change with:
71+
72+
$ snap set micro-ros-agent device="device path"
73+
74+
75+
grade: stable
76+
confinement: strict
77+
78+
architectures:
79+
- build-on: amd64
80+
- build-on: arm64
81+
- build-on: armhf
82+
- build-on: ppc64el
83+
84+
parts:
85+
86+
uros-agent:
87+
plugin: colcon
88+
source: .
89+
override-build: |
90+
git clone https://github.com/eProsima/Micro-XRCE-DDS-Agent.git -b $ROS_DISTRO
91+
git clone https://github.com/eProsima/Micro-CDR.git -b $ROS_DISTRO
92+
git clone https://github.com/micro-ROS/micro_ros_msgs.git -b $ROS_DISTRO
93+
git clone https://github.com/micro-ROS/rosidl_typesupport_microxrcedds.git -b $ROS_DISTRO
94+
git clone https://github.com/micro-ROS/rmw-microxrcedds.git -b $ROS_DISTRO
95+
. /opt/ros/$ROS_DISTRO/setup.sh
96+
colcon build --merge-install --install-base $SNAPCRAFT_PRIME --cmake-args '-DUAGENT_CLI_PROFILE=OFF -DUAGENT_BUILD_EXECUTABLE=OFF' --packages-up-to micro_ros_agent
97+
build-packages: [make, gcc, g++]
98+
stage-packages: [ros-foxy-ros2launch]
99+
100+
runner:
101+
plugin: dump
102+
source: snap/local/
103+
organize:
104+
'*': usr/bin/
105+
106+
apps:
107+
micro-ros-agent:
108+
command: lib/micro_ros_agent/micro_ros_agent
109+
environment:
110+
LD_LIBRARY_PATH: "$LD_LIBRARY_PATH:$SNAP/lib"
111+
plugs: [network, network-bind, serial-port]
112+
extensions: [ros2-foxy]
113+
114+
daemon:
115+
command: usr/bin/micro-ros-agent-daemon
116+
environment:
117+
LD_LIBRARY_PATH: "$LD_LIBRARY_PATH:$SNAP/lib"
118+
daemon: simple
119+
plugs: [network, network-bind, serial-port]

0 commit comments

Comments
 (0)