Commits

German Larrain committed fc9c19d

new SimpleArm executable, to demo a 3-links chain, connected by rotary joints

  • Participants
  • Parent commits 1330e66
  • Branches default

Comments (0)

Files changed (1)

File bin/SimpleArm.py

+#!/usr/bin/env python
+
+# Created on 2011.12.01
+# Last modified on 2011.12.01
+#
+# @author: german
+
+"""
+Runs a simulation of ...
+"""
+
+import sys
+
+from ars.app import Program
+import ars.utilities.mathematical as mut
+
+class SimpleArm(Program):
+	
+	TORQUE = 3
+	
+	def __init__(self):
+		Program.__init__(self)
+		self.key_press_functions.add('a', self.rotate_clockwise)
+		self.key_press_functions.add('z', self.rotate_counterlockwise)
+	
+	def create_sim_objects(self):
+		
+		x_axis = (1,0,0)
+		y_axis = (0,1,0)
+		z_axis = (0,0,1)
+		offset = (0,2,0)
+		
+		box = self.sim.add_box(1, (10,0.5,10), (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))
+		
+		self.sim.get_object(link1).rotate(x_axis, mut.pi/2)
+		self.sim.get_object(link3).rotate(x_axis, mut.pi/2)
+		
+		self.sim.add_rotary_joint('r1', 
+							self.sim.get_object(box), 
+							self.sim.get_object(link1), 
+							None, y_axis)
+		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)
+	
+	def rotate_clockwise(self):
+		self.sim.get_joint('r1').add_torque(self.TORQUE)
+		
+	def rotate_counterlockwise(self):
+		self.sim.get_joint('r1').add_torque(-self.TORQUE)
+
+if __name__ == '__main__':
+	print('this is SimpleArm.py')
+	a = SimpleArm()
+	a.start()
+	sys.exit(None)