mirror of
https://github.com/SHC-ASTRA/rover-ros2.git
synced 2026-02-11 09:20:40 +00:00
fix: correct turning direction
This commit is contained in:
@@ -217,7 +217,7 @@ class SerialRelay(Node):
|
|||||||
|
|
||||||
def cmd_vel_callback(self, msg: TwistStamped):
|
def cmd_vel_callback(self, msg: TwistStamped):
|
||||||
linear = msg.twist.linear.x
|
linear = msg.twist.linear.x
|
||||||
angular = msg.twist.angular.z
|
angular = -msg.twist.angular.z
|
||||||
|
|
||||||
vel_left_rads = (linear - (angular * CORE_WHEELBASE / 2)) / CORE_WHEEL_RADIUS
|
vel_left_rads = (linear - (angular * CORE_WHEELBASE / 2)) / CORE_WHEEL_RADIUS
|
||||||
vel_right_rads = (linear + (angular * CORE_WHEELBASE / 2)) / CORE_WHEEL_RADIUS
|
vel_right_rads = (linear + (angular * CORE_WHEELBASE / 2)) / CORE_WHEEL_RADIUS
|
||||||
@@ -235,13 +235,18 @@ class SerialRelay(Node):
|
|||||||
if abs(linear) > 1 or abs(angular) > 1:
|
if abs(linear) > 1 or abs(angular) > 1:
|
||||||
# if speed is greater than 1, then there is a problem
|
# if speed is greater than 1, then there is a problem
|
||||||
# make it look like a problem and don't just run away lmao
|
# make it look like a problem and don't just run away lmao
|
||||||
drive_speed = 0.25
|
linear = 0.25 * (linear / abs(linear))
|
||||||
|
angular = 0.25 * (angular / abs(angular))
|
||||||
|
|
||||||
duty_left = linear - angular
|
duty_left = linear - angular
|
||||||
duty_right = linear + angular
|
duty_right = linear + angular
|
||||||
scale = max(1, abs(duty_left), abs(duty_right))
|
scale = max(1, abs(duty_left), abs(duty_right))
|
||||||
duty_left /= scale
|
duty_left /= scale
|
||||||
duty_right /= scale
|
duty_right /= scale
|
||||||
|
|
||||||
|
if (linear < 0): # reverse direction when going backwards
|
||||||
|
duty_left *= -1
|
||||||
|
duty_right *= -1
|
||||||
|
|
||||||
command = f"can_relay_tovic,core,19,{duty_left},{duty_right}\n"
|
command = f"can_relay_tovic,core,19,{duty_left},{duty_right}\n"
|
||||||
self.send_cmd(command)
|
self.send_cmd(command)
|
||||||
|
|||||||
Reference in New Issue
Block a user