Commits

German Larrain committed 108c452

RSS1, VehicleWithArm:
-apply_torque_to_wheels moved to VehicleWithArm
-apply_torque_to_wheels now accepts two different torques, and go_forwards/backwords, turn_left/right use it

Comments (0)

Files changed (2)

 	
 	def compensate(self, sp, cv):
 		return (sp - cv) * self.kp
-	
-	def apply_torque_to_wheels(self, torque):
-		self.sim.get_joint('w1').add_torque(torque)
-		self.sim.get_joint('w2').add_torque(torque)
 
 if __name__ == '__main__':
 	a = RSS1()

bin/VehicleWithArm.py

 		
 	def go_forwards(self):
 		""" Rotate both powered wheels in the same direction, forwards """
-		self.sim.get_joint('w1').add_torque(self.WHEEL_TORQUE)
-		self.sim.get_joint('w2').add_torque(self.WHEEL_TORQUE)
+		self.apply_torque_to_wheels(self.WHEEL_TORQUE)
 	
 	def go_backwards(self):
 		""" Rotate both powered wheels in the same direction, backwards """
-		self.sim.get_joint('w1').add_torque(-self.WHEEL_TORQUE)
-		self.sim.get_joint('w2').add_torque(-self.WHEEL_TORQUE)
+		self.apply_torque_to_wheels(-self.WHEEL_TORQUE)
 		
 	def turn_left(self):
 		"""
 		Rotate both powered wheels in different directions,
 		with a global counter-clockwise rotation (from above).
 		"""
-		self.sim.get_joint('w1').add_torque(-self.WHEEL_TORQUE)
-		self.sim.get_joint('w2').add_torque(self.WHEEL_TORQUE)
+		self.apply_torque_to_wheels(-self.WHEEL_TORQUE, self.WHEEL_TORQUE)
 		
 	def turn_right(self):
 		"""
 		Rotate both powered wheels in different directions,
 		with a global clockwise rotation (from above).
 		"""
-		self.sim.get_joint('w1').add_torque(self.WHEEL_TORQUE)
-		self.sim.get_joint('w2').add_torque(-self.WHEEL_TORQUE)
+		self.apply_torque_to_wheels(self.WHEEL_TORQUE, -self.WHEEL_TORQUE)
 
 	def on_pre_step(self):
 		print(self.sim.get_object(self.chassis).get_position())
+	
+	def apply_torque_to_wheels(self, torque, torque2=None):
+		self.sim.get_joint('w1').add_torque(torque)
+		if torque2:
+			self.sim.get_joint('w2').add_torque(torque2)
+		else:
+			self.sim.get_joint('w2').add_torque(torque)
 
 if __name__ == '__main__':
 	a = VehicleWithArm(True)