Subscribe cmd_vel with Arduino
Hello,
I would want to send PWM signal with an arduino in order to control motors. But, as a beginner, I am not exactly sure of what to do. I need first to publish "cmd_vel". Then I need to write a node in Arduino which subscribe to "cmd_vel", right ?
If so, I am not confident with the code I wrote :
include "ros.h"
include "geometry_msgs/Twist.h"
ros::NodeHandle nh;
void velCallback(const geometry_msgs::Twist& vel) {
geometry_msgs::Twist new_vel = vel;
// HERE I WANT TO USE vel TO DEFINE PWM }
void setup() {
nh.initNode();
ros::Subscriber<geometry_msgs::Twist> ("cmd_vel", &velCallback);
}
void loop()
{
nh.spinOnce();
delay(1);
}
It is the right way to do ? And is that code correct ?
PS : Sorry but I don't how to properly insert cpp code citation
Regards,
Matt
looks ok. How are the motors connected? What kind of motors do you use? Which driver hardware do you use?
Do you have feedback? PWM isn't velocity control.
I don't want to make feedback control yet. I just want to use cmd_vel, like analogWrite(cmd_vel.linear.x). But currently when I run roscore, compile this arduino script, and run "rosrun rosserial_python serial_node.py /dev/ttyACM0". I just get this message : Connecting to /dev/ttyACM0 at 57600 baud
Someone know why I am stuck to 'Connecting to /dev/ttyACM0 at 57600 baud' ? And why i can't see my node working with 'rostopic list' ?
Firstly , you should update the question with what you tried and any new error message you have. Secondly, can you check if the serial node is working and sending out data?