I needed to connect my Arduino and Edison through serial connction.
First of all run the Arduino IDE an get the library “Rosserial” version 1.7.8 (for ROS Lunar). Upload the sketch:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#include <ros.h> #include <std_msgs/String.h> class NewHardware : public ArduinoHardware { public: NewHardware():ArduinoHardware(&Serial1, 9600){}; }; ros::NodeHandle_<NewHardware> nh; std_msgs::String str_msg; ros::Publisher chatter("chatter", &str_msg); char hello[13] = "hello world!"; void setup() { nh.initNode(); nh.advertise(chatter); } void loop() { str_msg.data = hello; chatter.publish( &str_msg ); nh.spinOnce(); delay(1000); } |
To do it we need to enable UART on the Edison board:
Info from http://www.emutexlabs.com/project/215-intel-edison-gpio-pin-multiplexing-guide: go to super user mode and input the commands:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# export all useful gpio echo 130 > echo 130 > /sys/class/gpio/export echo 248 > /sys/class/gpio/export echo 216 > /sys/class/gpio/export echo 131 > /sys/class/gpio/export echo 249 > /sys/class/gpio/export echo 217 > /sys/class/gpio/export echo 214 > /sys/class/gpio/export # Disable tri-state echo low > /sys/class/gpio/gpio214/direction # Set direction echo low > /sys/class/gpio/gpio248/direction echo high > /sys/class/gpio/gpio249/direction echo in > /sys/class/gpio/gpio216/direction echo in > /sys/class/gpio/gpio217/direction # Set Mode1 echo mode1 > /sys/kernel/debug/gpio_debug/gpio130/current_pinmux echo mode1 > /sys/kernel/debug/gpio_debug/gpio131/current_pinmux # Activate tri-state echo high > /sys/class/gpio/gpio214/direction exit |
Then create the catkin space and make the Rosserial drivers:
1 2 3 4 5 6 7 8 9 |
mkdir ~/sd/catkin_ws/src cd ~/sd/catkin_ws/src git clone https://github.com/ros/common_msgs.git git clone https://github.com/ros-drivers/rosserial.git cd ~/sd/catkin_ws catkin_make catkin_make install source ~/sd/catkin_ws/install/setup.bash source ~/sd/ros_catkin_ws/devel_isolated/setup.bash |
Now we can start roscore and rosserial:
1 2 3 |
roscore & rosrun rosserial_python serial_node.py _port:=/dev/ttyMFD1 & rostopic echo chatter |
Now we see:
1 2 3 4 5 6 7 |
data: "hello world!" --- data: "hello world!" --- data: "hello world!" --- data: "hello world!" |
If you have the error like this:
1 2 3 |
[ERROR] [1537204439.893275]: Creation of publisher failed: need more than 1 value to unpack [ERROR] [1537204440.857315]: Tried to publish before configured, topic id 125 [INFO] [1537204440.916866]: Requesting topics... |
Then an installed arduino rosserial library is mismatch.