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

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 teleop_twist_keyboard.py) 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},
                                        ignition::math::Vector3d{_msg->angular.x,_msg->angular.y,_msg->angular.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
2

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
0

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();
            model->SetLinearVel(ignition::math::Vector3d(
                    _msg->linear.x * cosf(yaw) - _msg->linear.y * sinf(yaw),
                    _msg->linear.y  * cosf(yaw) + _msg->linear.x * sinf(yaw),
                    0));
            model->SetAngularVel(ignition::math::Vector3d(0, 0, _msg->angular.z));
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

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

Seen: 731 times

Last updated: Jul 18 '18