0
$\begingroup$

Rosanswers logo

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.


Originally posted by robof83 on ROS Answers with karma: 1 on 2012-11-29

Post score: 0


Original comments

Comment by ipso on 2012-12-02:
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.

Comment by Harry on 2013-01-23:
have you got you code working? can you share it?

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

As far as I can tell, c.contact is an integer. I recommend you try:

c.contact = 1; 

and publish it. If that doesn't work, let's pick at it to see what it is. Try:

int test = c.contact; 
ROS_INFO("Contact value: %i", test);

and paste the output for us.

Another thing to consider: Most NXT launch files should provide the sensor data for you. Most would write a listener, then a publisher for motor commands.


Originally posted by allenh1 with karma: 3055 on 2012-11-30

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.