ros2_ws/src
run:
package.xml
file).
Untitled
mpu6050_node.py
(or whatever your sensor is called) under /ros2_ws/src/ei_ros2/ei_ros2
.
Float32MultiArray
as the message type, because we want to send an array with three readings (accelerometer X, Y, Z) which are float values.
read_mpu6050()
method is called. Each time the 3 accelerometer axes are read, and sent together in an array to the mpu6050_stream
topic. Once it arrives to the topic it becomes available for our machine learning node to subscribe to.main()
function, the full publisher node for the MPU6050 accelerometer is:
chmod +x mpu6050_node.py
to make your node file executable, since we’re using --symlink-install
Untitled
Untitled
/ros2_ws/src/ei_ros2/ei_ros2
).
Now let’s build the node!
Make a file called ei_node.py
(or something) under /ros2_ws/src/ei_ros2/ei_ros2
.
String
and Float32MultiArray
:
Float32MultiArray
for subscribing to the sensor node we just createdString
, for publishing the machine learning results to an inference streamDon’t stress too much about this part — if you put the wrong number in, you’ll get an error telling you what the correct number is 🙂
classify()
method returns a string with the name of the most likely result. Machine learning inferences look like: {'dog': 0.8, 'cat': 0.2, 'fish': 0.1}
. This function returns only the string with the highest probability.
main()
function and we’re ready to go!
Full Edge Impulse Pub/Sub code:
chmod +x ei_node.py
to make your node file executable.
[setup.py](http://setup.py)
file add entry points for your nodes:
ros2_ws
(or your main ROS2 workspace directory) and build the package using:
inference_stream
topic using:
inference_stream
topic:
nodes.gif