ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Ok, I got what the problem was. Basically, sensor_msgs classes/structs are defined differently for the ros_lib on Arduino. I had to specify the size of the message I'm sending, for example by defining variables like 'position_length' as in the following code:
sensor_msgs::JointState robot_state;
char *a[] = {"FL", "FR", "BR", "BL"}; // F: Front - B: Back - R: Right - L: Left
float pos[4]; /// stores arduino time
float vel[4];
float eff[4];
ros::Publisher odometry("odo", &robot_state);
SerialCommand serialCommand;
#define CAN_BUS_SPEED 1000 // 1Mbaud
int state = 0;
int pin = LOW;
byte received[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
byte rec [4] = {0x00, 0x00, 0x00, 0x00};
signed long rec_new;
void setup() {
// put your setup code here, to run once:
nh.initNode();
nh.advertise(chatter);
nh.advertise(odometry);
robot_state.header.frame_id = robot_id;
robot_state.name_length = 4;
robot_state.velocity_length = 4;
robot_state.position_length = 4; /// here used for arduino time
robot_state.effort_length = 4; /// here used for arduino time
robot_state.name = a;
robot_state.position = pos;
robot_state.velocity = vel;
robot_state.effort = eff;
After that It worked. Thanks for the help!