Need help with writing c++ code for NXT
I have an NXT robot that I've been (unsuccessfully trying to control)for the past few months. I went through all of the on-site basic tutorials, as well as the NXT tutorials. Unfortunately, I still feel as though I have very little idea as to what's actually going on. The NXT tutorials cover the robot description, but they stop there, and don't actually go on to cover programming the robot.
I've been trying to write c++ code to make a simple talker/listener for each of the sensors, but at this point it feels like I'm somewhat stabbing in the dark. I'm trying to follow the simple publisher/subscriber example in the tutorials, but it's just too different and doesn't really apply to what I'm trying to do. Currently I have this written
#include <ros/ros.h>
#include <nxt_msgs/Contact.h>
int main(int argc, char **argv)
{
ros::init(argc, argv, "touch_sensor_talker");
ros::NodeHandle n;
ros::Publisher pub = n.advertise<nxt_msgs::Contact>("touch_sensor", 1);
ros::Rate loop_rate(10);
nxt_msgs::Contact c;
c = Contact();
test = c.contact
pub.publish(c);
ros::spinOnce();
loop_rate.sleep();
return 0;
}
but it doesn't work. I've looked into the Contact.h file, but it's fairly difficult to understand what's going on in there. How do I create a Contact object and then publish that onto the touch_sensor topic? How then would I create a simple subscriber/listener?
I haven't really decided on an ultimate goal as of now; my short term goal is to just get simple talker/listeners up and running for the touch sensor, color sensor, and distance sensor.
I have been able to simulate automated movement by publishing onto the cmd_vel topic, but I did that by modifying per-existing nxt_teleop.cpp code, and not by writing it from scratch.
I'm a bit puzzled as to why you'd want to write a 'talker' for the sensors: ROS doesn't run 'on' the robot, all the
ros_nxt
pkgs do is let you communicate with the brick, which runs some proxies and transmits sensor data to the PC (via bluetooth or usb cable). Your PC runs ROS, not the brick.have you got you code working? can you share it?