From 4ee96157a64df53a8e66aa5f3f075cc4ceb73c6e Mon Sep 17 00:00:00 2001 From: "Wayne C. Gramlich" Date: Tue, 12 May 2015 17:16:29 -0700 Subject: [PATCH 1/3] Implemented ~motors_reversed parameter. Added ~left_motor_reversed and ~right_motor_reversed parameter. --- ros_arduino_python/config/arduino_params.yaml | 2 ++ .../src/ros_arduino_python/arduino_driver.py | 22 +++++++++++++++++++ .../src/ros_arduino_python/base_controller.py | 5 ++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ros_arduino_python/config/arduino_params.yaml b/ros_arduino_python/config/arduino_params.yaml index 9acbe3d..96513da 100644 --- a/ros_arduino_python/config/arduino_params.yaml +++ b/ros_arduino_python/config/arduino_params.yaml @@ -22,6 +22,8 @@ base_frame: base_link #encoder_resolution: 8384 # from Pololu for 131:1 motors #gear_reduction: 1.0 #motors_reversed: True +#left_motor_reversed: True +#right_motor_reversed: True # === PID parameters #Kp: 10 diff --git a/ros_arduino_python/src/ros_arduino_python/arduino_driver.py b/ros_arduino_python/src/ros_arduino_python/arduino_driver.py index f210d14..b9b6b2a 100755 --- a/ros_arduino_python/src/ros_arduino_python/arduino_driver.py +++ b/ros_arduino_python/src/ros_arduino_python/arduino_driver.py @@ -49,6 +49,9 @@ class Arduino: self.encoder_count = 0 self.writeTimeout = timeout self.interCharTimeout = timeout / 30. + self.motors_reversed = False + self.left_motor_reversed = False + self.right_motor_reversed = False # Keep things thread safe self.mutex = thread.allocate_lock() @@ -92,6 +95,12 @@ class Arduino: ''' self.port.close() + def motors_configure(motors_reversed = False, + left_motor_reversed = False, right_motor_reversed = False): + self.motors_reversed = motors_reversed + self.left_motor_reversed = left_motor_reversed + self.right_motor_reversed = right_motor_reversed + def send(self, cmd): ''' This command should not be used on its own: it is called by the execute commands below in a thread safe manner. @@ -267,6 +276,12 @@ class Arduino: raise SerialException return None else: + if self.motors_reversed: + values[0], values[1] = values[1], values[0] + if self.left_motor_reversed: + values[0] = -values[0] + if self.right_motor_reversed: + values[1] = -values[1] return values def reset_encoders(self): @@ -277,6 +292,13 @@ class Arduino: def drive(self, right, left): ''' Speeds are given in encoder ticks per PID interval ''' + if self.left_motor_reversed: + left = -left + if self.right_motor_reversed: + right = -right + if self.motors_reversed: + left, right = right, left + return self.execute_ack('m %d %d' %(right, left)) def drive_m_per_s(self, right, left): diff --git a/ros_arduino_python/src/ros_arduino_python/base_controller.py b/ros_arduino_python/src/ros_arduino_python/base_controller.py index 813e873..7c3b29c 100755 --- a/ros_arduino_python/src/ros_arduino_python/base_controller.py +++ b/ros_arduino_python/src/ros_arduino_python/base_controller.py @@ -50,7 +50,10 @@ class BaseController: self.accel_limit = rospy.get_param('~accel_limit', 0.1) self.motors_reversed = rospy.get_param("~motors_reversed", False) - + self.left_motor_reversed = rospy.get_param("~left_motor_reversed", False) + self.right_motor_reversed = rospy.get_param("~right_motor_reversed", False) + arduino.motors_configure(self.motors_reversed, self.left_motor_reverse, self.right_motor_reverse) + # Set up PID parameters and check for missing values self.setup_pid(pid_params) From 1d43339c009e196774937b4d47c003eef15e5d4a Mon Sep 17 00:00:00 2001 From: "Wayne C. Gramlich" Date: Wed, 13 May 2015 19:33:21 -0700 Subject: [PATCH 2/3] Fixed some typos. --- ros_arduino_python/src/ros_arduino_python/arduino_driver.py | 2 +- ros_arduino_python/src/ros_arduino_python/base_controller.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ros_arduino_python/src/ros_arduino_python/arduino_driver.py b/ros_arduino_python/src/ros_arduino_python/arduino_driver.py index b9b6b2a..ab48748 100755 --- a/ros_arduino_python/src/ros_arduino_python/arduino_driver.py +++ b/ros_arduino_python/src/ros_arduino_python/arduino_driver.py @@ -95,7 +95,7 @@ class Arduino: ''' self.port.close() - def motors_configure(motors_reversed = False, + def motors_configure(self, motors_reversed = False, left_motor_reversed = False, right_motor_reversed = False): self.motors_reversed = motors_reversed self.left_motor_reversed = left_motor_reversed diff --git a/ros_arduino_python/src/ros_arduino_python/base_controller.py b/ros_arduino_python/src/ros_arduino_python/base_controller.py index 7c3b29c..2d37526 100755 --- a/ros_arduino_python/src/ros_arduino_python/base_controller.py +++ b/ros_arduino_python/src/ros_arduino_python/base_controller.py @@ -52,7 +52,7 @@ class BaseController: self.motors_reversed = rospy.get_param("~motors_reversed", False) self.left_motor_reversed = rospy.get_param("~left_motor_reversed", False) self.right_motor_reversed = rospy.get_param("~right_motor_reversed", False) - arduino.motors_configure(self.motors_reversed, self.left_motor_reverse, self.right_motor_reverse) + arduino.motors_configure(self.motors_reversed, self.left_motor_reversed, self.right_motor_reversed) # Set up PID parameters and check for missing values self.setup_pid(pid_params) From 8963ce8c59573f14dee25394696a1d3f6cc7d765 Mon Sep 17 00:00:00 2001 From: "Wayne C. Gramlich" Date: Thu, 14 May 2015 08:54:55 -0700 Subject: [PATCH 3/3] Backed out changes that were accidently checked into hbrobotics repository. Explaination: I am president of Homebrew Roboics, so I am also an 'owner' of the hbrobotics repository. By accident, I checked in some untested changes into the hbrobotics web site, when I thought I was checking them into a staging repository. Me bad. This should get us back to the way we were at pull request #18. --- ros_arduino_python/config/arduino_params.yaml | 2 -- .../src/ros_arduino_python/arduino_driver.py | 22 ------------------- .../src/ros_arduino_python/base_controller.py | 5 +---- 3 files changed, 1 insertion(+), 28 deletions(-) diff --git a/ros_arduino_python/config/arduino_params.yaml b/ros_arduino_python/config/arduino_params.yaml index 96513da..9acbe3d 100644 --- a/ros_arduino_python/config/arduino_params.yaml +++ b/ros_arduino_python/config/arduino_params.yaml @@ -22,8 +22,6 @@ base_frame: base_link #encoder_resolution: 8384 # from Pololu for 131:1 motors #gear_reduction: 1.0 #motors_reversed: True -#left_motor_reversed: True -#right_motor_reversed: True # === PID parameters #Kp: 10 diff --git a/ros_arduino_python/src/ros_arduino_python/arduino_driver.py b/ros_arduino_python/src/ros_arduino_python/arduino_driver.py index ab48748..f210d14 100755 --- a/ros_arduino_python/src/ros_arduino_python/arduino_driver.py +++ b/ros_arduino_python/src/ros_arduino_python/arduino_driver.py @@ -49,9 +49,6 @@ class Arduino: self.encoder_count = 0 self.writeTimeout = timeout self.interCharTimeout = timeout / 30. - self.motors_reversed = False - self.left_motor_reversed = False - self.right_motor_reversed = False # Keep things thread safe self.mutex = thread.allocate_lock() @@ -95,12 +92,6 @@ class Arduino: ''' self.port.close() - def motors_configure(self, motors_reversed = False, - left_motor_reversed = False, right_motor_reversed = False): - self.motors_reversed = motors_reversed - self.left_motor_reversed = left_motor_reversed - self.right_motor_reversed = right_motor_reversed - def send(self, cmd): ''' This command should not be used on its own: it is called by the execute commands below in a thread safe manner. @@ -276,12 +267,6 @@ class Arduino: raise SerialException return None else: - if self.motors_reversed: - values[0], values[1] = values[1], values[0] - if self.left_motor_reversed: - values[0] = -values[0] - if self.right_motor_reversed: - values[1] = -values[1] return values def reset_encoders(self): @@ -292,13 +277,6 @@ class Arduino: def drive(self, right, left): ''' Speeds are given in encoder ticks per PID interval ''' - if self.left_motor_reversed: - left = -left - if self.right_motor_reversed: - right = -right - if self.motors_reversed: - left, right = right, left - return self.execute_ack('m %d %d' %(right, left)) def drive_m_per_s(self, right, left): diff --git a/ros_arduino_python/src/ros_arduino_python/base_controller.py b/ros_arduino_python/src/ros_arduino_python/base_controller.py index 2d37526..813e873 100755 --- a/ros_arduino_python/src/ros_arduino_python/base_controller.py +++ b/ros_arduino_python/src/ros_arduino_python/base_controller.py @@ -50,10 +50,7 @@ class BaseController: self.accel_limit = rospy.get_param('~accel_limit', 0.1) self.motors_reversed = rospy.get_param("~motors_reversed", False) - self.left_motor_reversed = rospy.get_param("~left_motor_reversed", False) - self.right_motor_reversed = rospy.get_param("~right_motor_reversed", False) - arduino.motors_configure(self.motors_reversed, self.left_motor_reversed, self.right_motor_reversed) - + # Set up PID parameters and check for missing values self.setup_pid(pid_params)