ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Please refer to this tutorial for further info: https://www.clearpathrobotics.com/assets/guides/kinetic/ros/Driving%20Husky%20with%20ROSSerial.html
#include <ArduinoHardware.h>
#include <ros.h>
#include <geometry_msgs/Twist.h>
ros::NodeHandle nh;
geometry_msgs::Twist msg;
ros::Publisher pub("husky/cmd_vel", &msg);
void setup()
{
nh.initNode();
nh.advertise(pub);
} void loop()
{
if(digitalRead(8)==1)
msg.linear.x=-0.25;
else if (digitalRead(4)==1)
msg.linear.x=0.25;
else if (digitalRead(8)==0 && digitalRead(4)==0)
msg.linear.x=0;
pub.publish(&msg);
nh.spinOnce();
}
As you can see a Twist
message is published to the cmd_vel
topic. Twist message is composed of Linear and Angular velocities as can be seen here:
Once code loaded in Arduino and publishing velocity commands, we can pass these messages along into our ROS environment through rosserial