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

How to convert Twist msg to PWM signals?

asked 2019-02-15 00:10:58 -0600

Asit gravatar image

I am designing a actuator module for my RC Car.

My joystick output a geometry_msgs/twist <> from which I extract the linear velocity and angular velocity. But I have to send 2 PWM signals (Power and Turn) to the dc motor and servo motor and I am unable to establish the relationship.

Power has a direct relationship with linear velocity. So that relation ship is easy. But for the angular velocity, how do I decide whether to change power or turn ??

edit retag flag offensive close merge delete

Comments

what kind of car are you using ? Diff_drive like a tank or like a normal car (ackerman_steering) ?

http://ros-developer.com/2017/11/09/a...

Dig here: https://github.com/dkarunakaran/robocar

ChriMo gravatar image ChriMo  ( 2019-02-15 01:24:21 -0600 )edit

I am using ackerman_steering

Asit gravatar image Asit  ( 2019-02-20 01:17:13 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-02-04 21:22:49 -0600

Droter gravatar image

This will convert the Twist to Ackermann messages: http://wiki.ros.org/teb_local_planner...

def convert_trans_rot_vel_to_steering_angle(v, omega, wheelbase):
  if omega == 0 or v == 0:
    return 0

  radius = v / omega
  return math.atan(wheelbase / radius)

v = data.linear.x
steering_angle = convert_trans_rot_vel_to_steering_angle(v, data.angular.z, wheelbase)

This will convert angular velocity to steering angle.
Once you have the steering angle you can send the servo PWM value that corresponds to that angle. Or put a control loop around your steering angle sensor.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-02-15 00:10:58 -0600

Seen: 1,716 times

Last updated: Feb 04 '20