ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

reference example for cmd_vel command subscriber

asked 2018-07-17 04:07:30 -0500

Tal Ma gravatar image

Hi, I would like to move a gazebo model using a twist messages (geometry_msgs/Twist) that come from keyboard input. I managed to run teleop_twist_keboard node (rosrun teleop_twist_keyboard to generate these messages. I tried to pipeline these messages to ros node that move my model using this code

   void OnTwistMsg(const geometry_msgs::TwistConstPtr &_msg) {
            this->model->SetWorldTwist (ignition::math::Vector3d{_msg->linear.x,_msg->linear.y,_msg->linear.z},
                    , true);

Assuming all nodes are correctly created and this message was subscribed properly. I'm not sure the model twist function is the right function to use. Can you point me to some reference code of similar subscriber? Should I use the Twist message ?

Thanks a lot Tal

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2018-07-17 17:00:13 -0500

kev-the-dev gravatar image

Looks like you're trying to make a gazebo plugin which subscribes to a ROS topic. This plugin does something similar and may be a helpful reference.

edit flag offensive delete link more

answered 2018-07-18 15:09:41 -0500

Tal Ma gravatar image

updated 2018-07-18 15:09:58 -0500

Thanks! that's exactly what I was looking for. In brief the twist message should be converted into velocity using this function

void OnTwistMsg(const geometry_msgs::TwistConstPtr &_msg) {
            auto yaw = (float)model->WorldPose().Rot().Yaw();
                    _msg->linear.x * cosf(yaw) - _msg->linear.y * sinf(yaw),
                    _msg->linear.y  * cosf(yaw) + _msg->linear.x * sinf(yaw),
            model->SetAngularVel(ignition::math::Vector3d(0, 0, _msg->angular.z));
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2018-07-17 04:04:20 -0500

Seen: 735 times

Last updated: Jul 18 '18