rosnode exercise

asked 2017-05-16 16:50:45 -0500

Gabss gravatar image

updated 2017-05-17 01:50:42 -0500

Hi everyone, i'm new to ros andall its features, i started learning about topics, messages, publisher/subscribers and i'm trying now to do some exercises. I found this in particular: "joypad_simulator: Write a node that receive input from keyboard and publish a sensor_msgs/Joy message on the same topic used by the joy_node node. At least the two main axes of each joystick and three buttons needs to be simulated." All i could do is this

define NAME_OF_THIS_NODE "joypad_simulator"
class ROSnode {
private:

    ros::NodeHandle Handle; 
    ros::Subscriber keyboardSub;    
    ros::Publisher cmdPub;      

    sensor_msgs::Twist out;

    void callback(const geometric_msgs::Joy::ConstPtr& msg);
public:
    void Prepare(); 
};

void ROSnode::Prepare() {
    keyboardSub = Handle.subscribe("joy", 10, &ROSnode::callback);
    cmdPub = Handle.advertise<geometric_msgs::Joy>("cmd_joy", 10);  
    ROS_INFO("Node %s ready to run.", ros::this_node::getName().c_str());
}

void ROSnode::callback(const geometric_msgs::Joy::ConstPtr& msg) {  //il metodo si aspetta messaggi di tipo sensore
    out.linear.x = maxLinear * msg->axes[1];
    out.angular.z = maxAngular * msg->axes[3];
     cmdPub.publish(out);
}

}

int main(int argc, char **argv) {
  ros::init(argc, argv, NAME_OF_THIS_NODE);     //inizializza il nodo
  ROSnode mNode;

  mNode.Prepare();
  return (0);
}

I know is not much, but that's all i can do by now, i tried to look for the turtlebot keyboard teleop code, but i can't find it. I would really appreciate the help and any sort of explanation

edit retag flag offensive close merge delete