Ask Your Question

reference example for cmd_vel command subscriber

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

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 -0600

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 -0600

Tal Ma gravatar image

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


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

Seen: 317 times

Last updated: Jul 18 '18