Commits

German Larrain  committed f860c71

new module ars.constants. It contains the definition of X, Y and Z unit vectors, as well as those pointing upwards, rightwards and outwards, as displayed by the graphics library.

  • Participants
  • Parent commits c0856c5

Comments (0)

Files changed (3)

File ars/constants.py

+
+# Created on 2012.01.29
+#
+# @author: german
+
+
+X_AXIS = (1,0,0)
+Y_AXIS = (0,1,0)
+Z_AXIS = (0,0,1)
+
+RIGHTWARDS_AXIS = X_AXIS
+UPWARDS_AXIS = Y_AXIS
+OUTWARDS_AXIS = Z_AXIS

File bin/SimpleArm.py

 
 from ars.app import Program
 import ars.utilities.mathematical as mut
+import ars.constants as cts
 
 class SimpleArm(Program):
 	
 	
 	def create_sim_objects(self):
 		
-		x_axis = (1,0,0)
-		y_axis = (0,1,0)
-		z_axis = (0,0,1)
 		#arm_offset = (0,0.5,0)
 		
 		box = self.sim.add_box(*self.BOX_PARAMS)
 		link2 = self.sim.add_capsule(*self.LINK2_PARAMS)
 		
 		# bodies are rotated before attaching themselves through joints
-		self.sim.get_object(link1).rotate(x_axis, mut.pi/2)
-		self.sim.get_object(link2).rotate(x_axis, mut.pi/2)
+		self.sim.get_object(link1).rotate(cts.X_AXIS, mut.pi/2)
+		self.sim.get_object(link2).rotate(cts.X_AXIS, mut.pi/2)
 		
 		self.sim.get_object(box).offset_by_position(self.OFFSET)
 		self.sim.get_object(link1).offset_by_position(self.OFFSET)
 		self.sim.add_rotary_joint('r1', 
 							self.sim.get_object(box), 
 							self.sim.get_object(link1), 
-							None, y_axis)
+							None, cts.Y_AXIS)
 		r2_anchor = mut.sub3(self.sim.get_object(link2).get_position(),
 							(0,self.LINK2_PARAMS[1]/2,0))
 		self.sim.add_rotary_joint('r2', 
 							self.sim.get_object(link1), 
 							self.sim.get_object(link2), 
-							r2_anchor, z_axis)
+							r2_anchor, cts.Z_AXIS)
 	
 	def rotate_clockwise(self):
 		self.sim.get_joint('r1').add_torque(self.TORQUE)

File bin/VehicleWithArm.py

 
 from ars.app import Program
 import ars.utilities.mathematical as mut
+import ars.constants as cts
 
 class VehicleWithArm(Program):
 	
 		Creates and sets up all the objects of the simulation.
 		'''
 		
-		x_axis = (1,0,0)
-		y_axis = (0,1,0)
-		z_axis = (0,0,1)
-		offset = self.VEHICLE_OFFSET
 		arm_offset = (0,0.5,0)
 		
 		#=======================================================================
 		self.sim.add_rotary_joint('w1', 
 							self.sim.get_object(chassis), 
 							self.sim.get_object(wheelR), 
-							None, z_axis)
+							None, cts.Z_AXIS)
 		self.sim.add_rotary_joint('w2', 
 							self.sim.get_object(chassis), 
 							self.sim.get_object(wheelL), 
-							None, z_axis)
+							None, cts.Z_AXIS)
 		self.sim.add_ball_socket_joint('bs', 
 								self.sim.get_object(chassis), 
 								self.sim.get_object(ball),
 								None)
 		
-		self.sim.get_object(wheelR).offset_by_position(offset)
-		self.sim.get_object(wheelL).offset_by_position(offset)
-		self.sim.get_object(ball).offset_by_position(offset)
-		self.sim.get_object(chassis).offset_by_position(offset)
+		self.sim.get_object(wheelR).offset_by_position(self.VEHICLE_OFFSET)
+		self.sim.get_object(wheelL).offset_by_position(self.VEHICLE_OFFSET)
+		self.sim.get_object(ball).offset_by_position(self.VEHICLE_OFFSET)
+		self.sim.get_object(chassis).offset_by_position(self.VEHICLE_OFFSET)
 		
 		#=======================================================================
 		# ROBOTIC ARM
 		link2 = self.sim.add_capsule(*self.LINK2_PARAMS)
 		
 		# bodies are rotated before attaching themselves through joints
-		self.sim.get_object(link1).rotate(x_axis, mut.pi/2)
-		self.sim.get_object(link2).rotate(x_axis, mut.pi/2)
+		self.sim.get_object(link1).rotate(cts.X_AXIS, mut.pi/2)
+		self.sim.get_object(link2).rotate(cts.X_AXIS, mut.pi/2)
 		
 		self.sim.get_object(link1).offset_by_object(self.sim.get_object(chassis))
 		self.sim.get_object(link1).offset_by_position(arm_offset)
 		self.sim.add_rotary_joint('r1', 
 							self.sim.get_object(chassis), 
 							self.sim.get_object(link1), 
-							None, y_axis)
+							None, cts.Y_AXIS)
 		r2_anchor = mut.sub3(self.sim.get_object(link2).get_position(),
 							(0,self.LINK2_PARAMS[1]/2,0))
 		self.sim.add_rotary_joint('r2', 
 							self.sim.get_object(link1), 
 							self.sim.get_object(link2), 
-							r2_anchor, z_axis)
+							r2_anchor, cts.Z_AXIS)
 		
 		# test
 		#print(self.sim.get_object(wheelR).get_actor().set_color((0.8,0,0)))