Commits

German Larrain committed 151e013

-CasterSim and VehicleSim renamed to Vehicle2 and Vehicle1

Comments (0)

Files changed (4)

bin/CasterSim.py

-#!/usr/bin/env python
-
-# Created on 2011.11.16
-# Last modified on 2011.11.22
-#
-# @author: german
-
-"""
-Runs a simulation of a vehicle with 2 powered wheels and a caster wheel.
-"""
-
-import sys
-
-from ars.app import Program
-
-class CasterSim(Program):
-	
-	TORQUE = 300
-	
-	def __init__(self):
-		Program.__init__(self)
-		self.key_press_functions.add('up', self.go_forwards)
-		self.key_press_functions.add('down', self.go_backwards)
-		self.key_press_functions.add('left', self.turn_left)
-		self.key_press_functions.add('right', self.turn_right)
-	
-	def create_sim_objects(self):
-		
-		z_axis = (0,0,1)
-		offset = (1,1,0)
-		
-		wheelR = self.sim.add_cylinder(1, 0.2, 0.3, (0,0,-0.5)) # POR: point of reference
-		wheelL = self.sim.add_cylinder(1, 0.2, 0.3, (0,0,0.5))
-		caster = self.sim.add_sphere(1, 0.3, (1,0,0))
-		chassis = self.sim.add_box(10, (2,0.4,1.5), (0.5,0.55,0))
-		
-		self.sim.add_rotary_joint('r1', 
-							self.sim.get_object(chassis), 
-							self.sim.get_object(wheelR), 
-							None, z_axis)
-		self.sim.add_rotary_joint('r2', 
-							self.sim.get_object(chassis), 
-							self.sim.get_object(wheelL), 
-							None, z_axis)
-		self.sim.add_ball_socket_joint('bs', 
-								self.sim.get_object(chassis), 
-								self.sim.get_object(caster),
-								None)
-		
-		self.sim.get_object(wheelR).offset_by_position(offset)
-		self.sim.get_object(wheelL).offset_by_position(offset)
-		self.sim.get_object(caster).offset_by_position(offset)
-		self.sim.get_object(chassis).offset_by_position(offset)
-	
-	def go_forwards(self):
-		""" Rotate both powered wheels in the same direction, forwards """
-		self.sim.get_joint('r1').add_torque(self.TORQUE)
-		self.sim.get_joint('r2').add_torque(self.TORQUE)
-	
-	def go_backwards(self):
-		""" Rotate both powered wheels in the same direction, backwards """
-		self.sim.get_joint('r1').add_torque(-self.TORQUE)
-		self.sim.get_joint('r2').add_torque(-self.TORQUE)
-		
-	def turn_left(self):
-		"""
-		Rotate both powered wheels in different directions,
-		with a global counter-clockwise rotation (from above).
-		"""
-		self.sim.get_joint('r1').add_torque(-self.TORQUE)
-		self.sim.get_joint('r2').add_torque(self.TORQUE)
-		
-	def turn_right(self):
-		self.sim.get_joint('r1').add_torque(self.TORQUE)
-		self.sim.get_joint('r2').add_torque(-self.TORQUE)
-
-if __name__ == '__main__':
-	print('this is CasterSim.py')
-	a = CasterSim()
-	a.start()
-	sys.exit(None)
+#!/usr/bin/env python
+
+# Created on 2011.11.16
+# Last modified on 2011.11.22
+#
+# @author: german
+
+import sys
+
+from ars.app import Program
+
+class VehicleSim(Program):
+	
+	TORQUE = 100
+	
+	def __init__(self):
+		Program.__init__(self)
+		self.key_press_functions.add('up', self.go_forwards)
+		self.key_press_functions.add('down', self.go_backwards)
+		self.key_press_functions.add('left', self.turn_left)
+		self.key_press_functions.add('right', self.turn_right)
+	
+	def create_sim_objects(self):
+		wheel1 = self.sim.add_cylinder(1, 0.1, 0.2, (1,1,1)) # POR: point of reference
+		
+		wheel2 = self.sim.add_cylinder(1, 0.1, 0.2, (0,0,1))
+		wheel3 = self.sim.add_cylinder(1, 0.1, 0.2, (1,0,0))
+		wheel4 = self.sim.add_cylinder(1, 0.1, 0.2, (1,0,1))
+		
+		chassis = self.sim.add_box(10, (1.3,0.2,0.6), (0.5,0,0.5))
+		
+		self.sim.get_object(wheel2).offset_by_object(self.sim.get_object(wheel1))
+		self.sim.get_object(wheel3).offset_by_object(self.sim.get_object(wheel1))
+		self.sim.get_object(wheel4).offset_by_object(self.sim.get_object(wheel1))
+		self.sim.get_object(chassis).offset_by_object(self.sim.get_object(wheel1))
+		
+		self.sim.add_rotary_joint('r1', self.sim.get_object(chassis), self.sim.get_object(wheel1), (1,1,1), (0,0,1))
+		self.sim.add_rotary_joint('r2', self.sim.get_object(chassis), self.sim.get_object(wheel2), (1,1,2), (0,0,1))
+		self.sim.add_rotary_joint('r3', self.sim.get_object(chassis), self.sim.get_object(wheel3), (2,1,1), (0,0,1))
+		self.sim.add_rotary_joint('r4', self.sim.get_object(chassis), self.sim.get_object(wheel4), (2,1,2), (0,0,1))
+	
+	def go_forwards(self):
+		self.sim.get_joint('r1').add_torque(self.TORQUE)
+		self.sim.get_joint('r2').add_torque(self.TORQUE)
+	
+	def go_backwards(self):
+		self.sim.get_joint('r1').add_torque(-self.TORQUE)
+		self.sim.get_joint('r2').add_torque(-self.TORQUE)
+		
+	def turn_left(self):
+		self.sim.get_joint('r1').add_torque(-self.TORQUE/2)
+		self.sim.get_joint('r3').add_torque(-self.TORQUE/2)
+		self.sim.get_joint('r2').add_torque(self.TORQUE/2)
+		self.sim.get_joint('r4').add_torque(self.TORQUE/2)
+		
+	def turn_right(self):
+		self.sim.get_joint('r1').add_torque(self.TORQUE/2)
+		self.sim.get_joint('r3').add_torque(self.TORQUE/2)
+		self.sim.get_joint('r2').add_torque(-self.TORQUE/2)
+		self.sim.get_joint('r4').add_torque(-self.TORQUE/2)
+
+if __name__ == '__main__':
+	print('this is VehicleSim.py')
+	a = VehicleSim()
+	a.start()
+	sys.exit(None)
+#!/usr/bin/env python
+
+# Created on 2011.11.16
+# Last modified on 2011.11.22
+#
+# @author: german
+
+"""
+Runs a simulation of a vehicle with 2 powered wheels and a caster wheel.
+"""
+
+import sys
+
+from ars.app import Program
+
+class CasterSim(Program):
+	
+	TORQUE = 300
+	
+	def __init__(self):
+		""" Constructor, calls first the superclass constructor. """
+		Program.__init__(self)
+		self.key_press_functions.add('up', self.go_forwards)
+		self.key_press_functions.add('down', self.go_backwards)
+		self.key_press_functions.add('left', self.turn_left)
+		self.key_press_functions.add('right', self.turn_right)
+	
+	def create_sim_objects(self):
+		'''
+		Implementation of the required method.
+		Creates and sets up all the objects of the simulation.
+		'''
+		
+		z_axis = (0,0,1)
+		offset = (3,1,3)
+		
+		wheelR = self.sim.add_cylinder(1, 0.2, 0.3, (0,0,-0.5))
+		wheelL = self.sim.add_cylinder(1, 0.2, 0.3, (0,0,0.5))
+		caster = self.sim.add_sphere(1, 0.3, (1,0,0))
+		chassis = self.sim.add_box(10, (2,0.2,1.5), (0.5,0.45,0))
+		
+		self.sim.add_rotary_joint('r1', 
+							self.sim.get_object(chassis), 
+							self.sim.get_object(wheelR), 
+							None, z_axis)
+		self.sim.add_rotary_joint('r2', 
+							self.sim.get_object(chassis), 
+							self.sim.get_object(wheelL), 
+							None, z_axis)
+		self.sim.add_ball_socket_joint('bs', 
+								self.sim.get_object(chassis), 
+								self.sim.get_object(caster),
+								None)
+		
+		self.sim.get_object(wheelR).offset_by_position(offset)
+		self.sim.get_object(wheelL).offset_by_position(offset)
+		self.sim.get_object(caster).offset_by_position(offset)
+		self.sim.get_object(chassis).offset_by_position(offset)
+		
+		# test
+		#print(self.sim.get_object(wheelR).get_actor().set_color((0.8,0,0)))
+	
+	
+	def go_forwards(self):
+		""" Rotate both powered wheels in the same direction, forwards """
+		self.sim.get_joint('r1').add_torque(self.TORQUE)
+		self.sim.get_joint('r2').add_torque(self.TORQUE)
+	
+	def go_backwards(self):
+		""" Rotate both powered wheels in the same direction, backwards """
+		self.sim.get_joint('r1').add_torque(-self.TORQUE)
+		self.sim.get_joint('r2').add_torque(-self.TORQUE)
+		
+	def turn_left(self):
+		"""
+		Rotate both powered wheels in different directions,
+		with a global counter-clockwise rotation (from above).
+		"""
+		self.sim.get_joint('r1').add_torque(-self.TORQUE)
+		self.sim.get_joint('r2').add_torque(self.TORQUE)
+		
+	def turn_right(self):
+		"""
+		Rotate both powered wheels in different directions,
+		with a global clockwise rotation (from above).
+		"""
+		self.sim.get_joint('r1').add_torque(self.TORQUE)
+		self.sim.get_joint('r2').add_torque(-self.TORQUE)
+
+if __name__ == '__main__':
+	print('this is CasterSim.py')
+	a = CasterSim()
+	a.start()
+	sys.exit(None)

bin/VehicleSim.py

-#!/usr/bin/env python
-
-# Created on 2011.11.16
-# Last modified on 2011.11.22
-#
-# @author: german
-
-import sys
-
-from ars.app import Program
-
-class VehicleSim(Program):
-	
-	TORQUE = 100
-	
-	def __init__(self):
-		Program.__init__(self)
-		self.key_press_functions.add('up', self.go_forwards)
-		self.key_press_functions.add('down', self.go_backwards)
-		self.key_press_functions.add('left', self.turn_left)
-		self.key_press_functions.add('right', self.turn_right)
-	
-	def create_sim_objects(self):
-		wheel1 = self.sim.add_cylinder(1, 0.1, 0.2, (1,1,1)) # POR: point of reference
-		
-		wheel2 = self.sim.add_cylinder(1, 0.1, 0.2, (0,0,1))
-		wheel3 = self.sim.add_cylinder(1, 0.1, 0.2, (1,0,0))
-		wheel4 = self.sim.add_cylinder(1, 0.1, 0.2, (1,0,1))
-		
-		chassis = self.sim.add_box(10, (1.3,0.2,0.6), (0.5,0,0.5))
-		
-		self.sim.get_object(wheel2).offset_by_object(self.sim.get_object(wheel1))
-		self.sim.get_object(wheel3).offset_by_object(self.sim.get_object(wheel1))
-		self.sim.get_object(wheel4).offset_by_object(self.sim.get_object(wheel1))
-		self.sim.get_object(chassis).offset_by_object(self.sim.get_object(wheel1))
-		
-		self.sim.add_rotary_joint('r1', self.sim.get_object(chassis), self.sim.get_object(wheel1), (1,1,1), (0,0,1))
-		self.sim.add_rotary_joint('r2', self.sim.get_object(chassis), self.sim.get_object(wheel2), (1,1,2), (0,0,1))
-		self.sim.add_rotary_joint('r3', self.sim.get_object(chassis), self.sim.get_object(wheel3), (2,1,1), (0,0,1))
-		self.sim.add_rotary_joint('r4', self.sim.get_object(chassis), self.sim.get_object(wheel4), (2,1,2), (0,0,1))
-	
-	def go_forwards(self):
-		self.sim.get_joint('r1').add_torque(self.TORQUE)
-		self.sim.get_joint('r2').add_torque(self.TORQUE)
-	
-	def go_backwards(self):
-		self.sim.get_joint('r1').add_torque(-self.TORQUE)
-		self.sim.get_joint('r2').add_torque(-self.TORQUE)
-		
-	def turn_left(self):
-		self.sim.get_joint('r1').add_torque(-self.TORQUE/2)
-		self.sim.get_joint('r3').add_torque(-self.TORQUE/2)
-		self.sim.get_joint('r2').add_torque(self.TORQUE/2)
-		self.sim.get_joint('r4').add_torque(self.TORQUE/2)
-		
-	def turn_right(self):
-		self.sim.get_joint('r1').add_torque(self.TORQUE/2)
-		self.sim.get_joint('r3').add_torque(self.TORQUE/2)
-		self.sim.get_joint('r2').add_torque(-self.TORQUE/2)
-		self.sim.get_joint('r4').add_torque(-self.TORQUE/2)
-
-if __name__ == '__main__':
-	print('this is VehicleSim.py')
-	a = VehicleSim()
-	a.start()
-	sys.exit(None)