Commits

German Larrain committed 8d9eb1b

robots.joints: added class 'Slider'

  • Participants
  • Parent commits 11d800b
  • Branches dev-joints

Comments (0)

Files changed (1)

File ars/model/robot/joints.py

 			raise exc.PhysicsObjectCreationError(type='Ball and Socket joint')
 
 
+class Slider(ActuatedJoint):
+
+	"""Joint with one DOF that constrains two objects to line up along an axis.
+
+	It is different from a Piston joint (which has two DOF) in that the Slider
+	does not allow rotation.
+
+	"""
+
+	def __init__(self, world, body1, body2, axis):
+
+		try:
+			inner_joint = ode.SliderJoint(world._inner_object)
+			inner_joint.attach(body1.inner_object, body2.inner_object)
+			inner_joint.setAxis(axis)
+
+			# TODO: necessary?
+			# see http://ode-wiki.org/wiki/index.php?title=Manual:_Joint_Types_and_Functions#Parameter_Functions
+			lo_stop = -ode.Infinity
+			hi_stop = ode.Infinity
+			inner_joint.setParam(ode.ParamLoStop, lo_stop)
+			inner_joint.setParam(ode.ParamHiStop, hi_stop)
+
+			super(Slider, self).__init__(world, inner_joint, body1, body2)
+		except:
+			raise exc.PhysicsObjectCreationError(type='Slider joint')
+
+	def add_force(self, force):
+		"""Apply a force of magnitude ``force`` along the joint's axis.
+
+		:type force: :class:`float`
+
+		"""
+		dispatcher.send(signals.JOINT_PRE_ADD_FORCE, sender=self,
+			force=force)
+		try:
+			self._inner_joint.addForce(force)
+		except:
+			raise exc.JointError(self, 'Failed to add force to this joint')
+		dispatcher.send(signals.JOINT_POST_ADD_FORCE, sender=self,
+			force=force)
+
+	@property
+	def position(self):
+		"""Return position of the joint with respect to its initial position.
+
+		The zero position is established when the joint's axis is set.
+
+		:rtype: :class:`float`
+
+		"""
+		try:
+			return self._inner_joint.getPosition()
+		except:
+			raise exc.JointError(self, 'Failed to get the position')
+
+	@property
+	def position_rate(self):
+		"""Return position's time derivative, i.e. "speed".
+
+		:rtype: :class:`float`
+
+		"""
+		try:
+			return self._inner_joint.getPositionRate()
+		except:
+			raise exc.JointError(self, 'Failed to get the position rate')
+
+
 class JointFeedback:
 	def __init__(self, body1, body2, force1=None, force2=None, torque1=None,
 			torque2=None):