This section requires the catkin_ws to be initialized and the turtlebot_dabit package created.
Please click here to learn how to initialize the catkin workspace
This section requires the rosserial_arduino package to be setup.
Please click here to learn how to set up rosserial_arduino
As an example to send data to the Arduino, we will use the blink example.o
tutorial. More informatino can be pulled up, here
/* rosserial Subscriber Example */
#include <ros.h>
#include <std_msgs/Bool.h>
ros::NodeHandle nh;
void messageCb( const std_msgs::Bool& msg){
digitalWrite(13, msg.data); // set the pin state to the message data
}
ros::Subscriber<std_msgs::Bool> sub("/arduino/led", &messageCb );
void setup()
{
pinMode(13, OUTPUT);
nh.initNode();
nh.subscribe(sub);
}
void loop()
{
nh.spinOnce();
delay(1);
}
source ~/catkin_ws/devel/setup.sh
roslaunch turtlebot_dabit arduino.launch
rostopic list
rostopic pub /arduino/led std_msgs/Bool True
rostopic pub /arduino/led std_msgs/Bool False
ROSSERIAL has recently improved their tutorials, and have a very wide selection of examples. Check out the ROSSerial_Arduino Tutorials