Skip to content

Commit 72f37ac

Browse files
committed
fix hbrobotics#10 issue
1 parent 589d670 commit 72f37ac

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

ros_arduino_python/src/ros_arduino_python/arduino_driver.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import os, time, sys, traceback
2727
from serial.serialutil import SerialException, SerialTimeoutException
2828
from serial import Serial
29+
import rospy
2930

3031
SERVO_MAX = 180
3132
SERVO_MIN = 0
@@ -47,7 +48,7 @@ def __init__(self, port="/dev/ttyUSB0", baudrate=57600, timeout=0.5):
4748
self.encoder_count = 0
4849
self.writeTimeout = timeout
4950
self.interCharTimeout = timeout / 30.
50-
51+
self.motors_reversed = rospy.get_param("~motors_reversed", False)
5152
# Keep things thread safe
5253
self.mutex = thread.allocate_lock()
5354

@@ -268,6 +269,8 @@ def get_encoder_counts(self):
268269
raise SerialException
269270
return None
270271
else:
272+
if self.motors_reversed:
273+
values[0], values[1] = -values[0], -values[1]
271274
return values
272275

273276
def reset_encoders(self):
@@ -278,6 +281,8 @@ def reset_encoders(self):
278281
def drive(self, right, left):
279282
''' Speeds are given in encoder ticks per PID interval
280283
'''
284+
if self.motors_reversed:
285+
left, right = -left, -right
281286
return self.execute_ack('m %d %d' %(right, left))
282287

283288
def drive_m_per_s(self, right, left):

0 commit comments

Comments
 (0)