Extract linear velocity

asked 2020-09-15 09:43:20 -0500

gabo07 gravatar image

Greetings, dear community! I was wondering if you could help with some questions. I'm a college student and a beginner at using ROS, and right now I'm trying to implement a trajectory tracking algorithm for a differential robot. I'm using as a base a open model Gazebo simulation available on https://docs.neobotix.de/display/ROSS..., and I wrote my nodes for the algorithm. The problem that I'm facing right now is I don't know from which topic of the simulation I should take the reading of the wheels previous velocities needed for the program. The last attempt I did was to subscribe to the joint topic to get the wheels angular displacement to obtain the wheel angular velocity and multiply the result by the wheel radius, and get in this way the wheel previous linear velocity. But the robot didn't performance as I was expecting. The work I've done so far can be found on https://gitlab.com/ga_07/electrical-p..., inside my_simulation directory. I will appreciate any help you can give me!

edit retag flag offensive close merge delete


But the robot didn't performance as I was expecting.

What did you expect and what did you get? Instead of describing your approach can you please show us (i.e., paste the relevant code directly into your question)

jayess gravatar image jayess  ( 2020-09-15 18:41:15 -0500 )edit

enter code here

from sensor_msgs.msg import JointState

self.joint_sub = rospy.Subscriber("joint_states", JointState, self.joint_callback, queue_size=100)

def joint_move(self):
    if (self.Ts == 0):
        self.Ts = 0.01
    if((self.x_n != 0) and (self.y_n != 0)):
        self.wxk_1 = (self.x_n - self.x_n_1)/self.Ts
        self.wyk_1 = (self.y_n - self.y_n_1)/self.Ts
        self.vxk_1 = self.R * self.wxk_1
        self.vyk_1 = self.R * self.wyk_1
        self.x_n_1 = self.x_n
        self.y_n_1 = self.y_n
        if (self.debug == True):
            print("self.wxk_1: ", self.wxk_1)
            print("self.wyk_1: ", self.wyk_1)
            print("self.vxk_1: ", self.vxk_1)
            print("self.vyk_1: ", self.vyk_1)

def joint_callback(self, msg):
    self.x_n = msg.position[0]
    self.y_n = msg.position[1]
gabo07 gravatar image gabo07  ( 2020-09-16 16:33:16 -0500 )edit

Sure! Here's a part of my code in which I have the question. I'm trying to get the linear velocity from each wheel (that's what I was expecting), so I tried a subscription to joint_state topic to obtain the wheel displacement measured on radians. Using those data, I calculated the angular velocity and then multiply it by wheel radius to finally have the linear velocity. I'm not sure if this is a correct way to get those values and I think this could be one of the mistakes on my simulation. I'll be thankful for any advice or help you can give me

gabo07 gravatar image gabo07  ( 2020-09-16 16:46:34 -0500 )edit