Robotics StackExchange | Archived questions

reference example for cmd_vel command subscriber

Hi, I would like to move a gazebo model using a twist messages (geometrymsgs/Twist) that come from keyboard input. I managed to run teleoptwistkeboard node (rosrun teleoptwistkeyboard teleoptwist_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

Asked by Tal Ma on 2018-07-17 04:04:20 UTC

Comments

Answers

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.

Asked by kev-the-dev on 2018-07-17 17:00:13 UTC

Comments

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));
}

Asked by Tal Ma on 2018-07-18 15:09:41 UTC

Comments