Commits

German Larrain committed 0caa0f5

SimpleArm demo: changes analogous to those made in VehicleWithArm

Comments (0)

Files changed (1)

 # @author: german
 
 """
-Runs a simulation of a simple arm, with 3 links and 3 rotary joints
+Runs a simulation of a simple arm, with 2 links and 2 rotary joints
 """
 
 import sys
 	
 	TORQUE = 3
 	
+	OFFSET = (2.5,1,2.5)
+	
+	BOX_PARAMS = (1,(3,0.5,3),(0,-0.75,0)) # (density, size, center)
+	LINK1_PARAMS = (1,0.8, 0.1,(0,0,0)) # (density, length, radius, center)
+	LINK2_PARAMS = (1,0.6,0.1,(0,0.7,0.2))
+	
 	def __init__(self):
 		Program.__init__(self)
 		self.key_press_functions.add('a', self.rotate_clockwise)
 		x_axis = (1,0,0)
 		y_axis = (0,1,0)
 		z_axis = (0,0,1)
-		offset = (2.5,2,2.5)
+		#arm_offset = (0,0.5,0)
 		
-		box = self.sim.add_box(1, (3,0.5,3), (0,-0.75,0))
-		link1 = self.sim.add_cylinder(1, 0.8, 0.1, (0,0,0))
-		link2 = self.sim.add_cylinder(1, 0.8, 0.1, (0,0.5,0.5))
-		link3 = self.sim.add_cylinder(1, 0.8, 0.1, (0,1,1))
+		box = self.sim.add_box(*self.BOX_PARAMS)
+		link1 = self.sim.add_capsule(*self.LINK1_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(link3).rotate(x_axis, mut.pi/2)
+		self.sim.get_object(link2).rotate(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.get_object(link2).offset_by_position(self.OFFSET)
+		#=======================================================================
+		# self.sim.get_object(link1).offset_by_object(self.sim.get_object(box))
+		# self.sim.get_object(link1).offset_by_position(arm_offset)
+		# self.sim.get_object(link2).offset_by_object(self.sim.get_object(link1))
+		#=======================================================================
 		
 		self.sim.add_rotary_joint('r1', 
 							self.sim.get_object(box), 
 							self.sim.get_object(link1), 
 							None, 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), 
-							None, z_axis)
-		self.sim.add_rotary_joint('r3', 
-							self.sim.get_object(link2), 
-							self.sim.get_object(link3), 
-							None, y_axis)
-		
-		self.sim.get_object(box).offset_by_position(offset)
-		self.sim.get_object(link1).offset_by_position(offset)
-		self.sim.get_object(link2).offset_by_position(offset)
-		self.sim.get_object(link3).offset_by_position(offset)
+							r2_anchor, z_axis)
 	
 	def rotate_clockwise(self):
 		self.sim.get_joint('r1').add_torque(self.TORQUE)
 		self.sim.get_joint('r1').add_torque(-self.TORQUE)
 
 if __name__ == '__main__':
-	print('this is SimpleArm.py')
+	print('Python file being executed: %s' % __file__)
 	a = SimpleArm()
 	a.start()
 	sys.exit(None)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.