Commits

German Larrain  committed eef2cf6

no code changes: just whitespace, comments and docstrings (minimal)

  • Participants
  • Parent commits ef639f1

Comments (0)

Files changed (6)

File ars/model/collision/adapters.py

 
 
 class OdeEngine(base.Engine):
-	"""Adapter to the ODE collision engine"""
 
-#	def __init__(self):
-#		pass
+	"""Adapter to the ODE collision engine."""
 
 	#==========================================================================
 	# Functions and methods not overriding base class functions and methods
 		if OdeEngine.is_ray(geom1):
 			if OdeEngine.is_ray(geom2):
 				print('Weird, ODE says two rays may collide. '
-					  'That case is not handled.')
+				      'That case is not handled.')
 				return
 			else:
 				ray_geom = geom1

File ars/model/collision/base.py

 
 
 class Ray(Geom):
+
 	"""
 	Ray aligned along the Z-axis by default.
 	"A ray is different from all the other geom classes in that it does not
 	represent a solid object. It is an infinitely thin line that starts from
 	the geom's position and	extends in the direction of the geom's local
 	Z-axis." (ODE Wiki Manual)
+
 	"""
+
 	__metaclass__ = ABCMeta
 
 	@abstractmethod
 		pass
 
 	def get_last_contact(self):
-		"""Returns the contact object corresponding to the last collision of
+		"""Return the contact object corresponding to the last collision of
 		the ray with another geom. Note than in each simulation step, several
 		collisions may occur, one for each intersection geom (in ODE).
 		The object returned may or may not be the same returned by
 		`get_closer_contact`.
+
 		"""
 		return self._last_contact
 
 	def get_closer_contact(self):
-		"""Returns the contact object corresponding to the collision closest to
+		"""Return the contact object corresponding to the collision closest to
 		the ray's origin.
+
 		It may or may not be the same object returned by `get_last_contact`.
+
 		"""
 		return self._closer_contact
 
 	def set_last_contact(self, last_contact):
-		"""Sets the last contact object with which the ray collided. It also
+		"""Set the contact data of ray's last collision. It also
 		checks if `last_contact` is closer than the previously existing one.
 		The result can be obtained with the `get_closer_contact` method.
 		"""

File ars/model/physics/base.py

 
 
 class Engine(object):
+
 	__metaclass__ = ABCMeta
 
 	world_class = None
 
-#	@abstractmethod
-#	def __init__(self):
-#		raise NotImplementedError()
-
 
 class World(object):
+
 	__metaclass__ = ABCMeta
 
 	@abstractmethod
 
 
 class Body(object):
+
 	__metaclass__ = ABCMeta
 
 	@abstractmethod
 	def __init__(self, mass=None, density=None, pos=None, rot=None,
-			*args, **kwargs):
+	             *args, **kwargs):
 
 		if mass is not None:
 			if density is not None:
 
 
 class Box(Body):
+
 	__metaclass__ = ABCMeta
 
 	def __init__(self, size, *args, **kwargs):
 
 
 class Cone(Body):
+
 	__metaclass__ = ABCMeta
 
 	def __init__(self, height, radius, *args, **kwargs):
 
 
 class Sphere(Body):
+
 	__metaclass__ = ABCMeta
 
 	def __init__(self, radius, *args, **kwargs):
 
 
 class Cylinder(Body):
+
 	__metaclass__ = ABCMeta
 
 	def __init__(self, length, radius, *args, **kwargs):
 
 
 class Capsule(Body):
+
 	__metaclass__ = ABCMeta
 
 	def __init__(self, length, radius, *args, **kwargs):

File ars/model/robot/joints.py

 	def add_force(self, force):
 		"""Apply a force of magnitude ``force`` along the joint's axis.
 
-		:type force: :class:`float`
+		:type force: float
 
 		"""
 		dispatcher.send(signals.JOINT_PRE_ADD_FORCE, sender=self, force=force)
 
 		The zero position is established when the joint's axis is set.
 
-		:rtype: :class:`float`
+		:rtype: float
 
 		"""
 		try:
 	def position_rate(self):
 		"""Return position's time derivative, i.e. "speed".
 
-		:rtype: :class:`float`
+		:rtype: float
 
 		"""
 		try:

File ars/model/robot/sensors.py

 		Override this to define it based on some object's state or property.
 
 		:return: time value for the data
-		:rtype: :class:`float` or None
+		:rtype: float or None
 
 		"""
 		time = None
 
 		# subscribe :meth:`on_send` handler to the signal sent by ``sender``
 		dispatcher.connect(self.on_send, signal=self._signal,
-			sender=self._sender)
+		                   sender=self._sender)
 
 
 class MultipleSignalsSensor(BaseSignalSensor):
 		# sent by ``sender``
 		for signal in self._signals:
 			dispatcher.connect(self.on_send, signal=signal,
-				sender=self._sender)
+			                   sender=self._sender)
 
 
 class BodySensor(Sensor):
 	"""Sensor measuring the angle (and its rate) of a rotary joint."""
 
 	def _build_data(self):
-		kwargs = {
-			'angle': self.joint.angle,
-			'angle_rate': self.joint.angle_rate,
-			}
+		kwargs = {'angle': self.joint.angle,
+		          'angle_rate': self.joint.angle_rate, }
 		return SensorData(**kwargs)
 
 
 		# :class:`SimulatedJoint` wraps the "real" joint object that sends the
 		# signal.
 		super(JointTorque, self).__init__(signal=self.signal,
-			sender=sim_joint.joint)
+		                                  sender=sim_joint.joint)
 		self._sim = sim
 
 	def _build_data(self, sender, *args, **kwargs):
 
 	def __init__(self, sim_joint, sim):
 		super(JointForce, self).__init__(signal=self.signal,
-			sender=sim_joint.joint)
+		                                 sender=sim_joint.joint)
 		self._sim = sim
 
 	def _build_data(self, sender, *args, **kwargs):
 	"""Sensor measuring power applied by a joint (due to force and torque)."""
 
 	signals = [JointTorque.signal, JointForce.signal]
-	
+
 	def __init__(self, sim_joint, sim):
 		super(JointPower, self).__init__(signals=self.signals,
-			sender=sim_joint.joint)
+		                                 sender=sim_joint.joint)
 		self._sim = sim
 
 	def _build_data(self, sender, *args, **kwargs):
 			print('Error when calculating power. Exception:\n%s' % e)
 
 		return SensorData(**{'power': power})
-	
+
 	def _get_time(self):
 		return self._sim.sim_time
 
 
 	def _build_data(self):
 		kwargs = {'linear velocity': self.body.get_linear_velocity(),
-					'angular velocity': self.body.get_angular_velocity(), }
+		          'angular velocity': self.body.get_angular_velocity(), }
 		return SensorData(**kwargs)
 
 
 		angular_vel = self.body.get_angular_velocity()
 		self.body.save_velocities()
 
-		linear_accel = calc_acceleration(self._time_step,
-			linear_vel_prev, linear_vel)
-		angular_accel = calc_acceleration(self._time_step,
-			angular_vel_prev, angular_vel)
+		linear_accel = calc_acceleration(
+			self._time_step, linear_vel_prev, linear_vel)
+		angular_accel = calc_acceleration(
+			self._time_step, angular_vel_prev, angular_vel)
 
 		kwargs = {'linear acceleration': linear_accel,
-				  'angular acceleration': angular_accel, }
+		          'angular acceleration': angular_accel, }
 		return SensorData(**kwargs)
 
 
 		angular_ke = self.body.calc_rotation_kinetic_energy()
 
 		if self._disaggregate:
-			kwargs = {
-				'potential energy': potential_e,
-				'kinetic energy': linear_ke + angular_ke, }
+			kwargs = {'potential energy': potential_e,
+			          'kinetic energy': linear_ke + angular_ke, }
 		else:
 			kwargs = {'total energy': potential_e + linear_ke + angular_ke, }
 		return SensorData(**kwargs)
 			angular_ke += body.calc_rotation_kinetic_energy()
 
 		if self._disaggregate:
-			kwargs = {
-				'potential energy': potential_e,
-				'kinetic energy': linear_ke + angular_ke, }
+			kwargs = {'potential energy': potential_e,
+			          'kinetic energy': linear_ke + angular_ke, }
 		else:
 			kwargs = {'total energy': potential_e + linear_ke + angular_ke, }
 		return SensorData(**kwargs)

File ars/model/simulator/__init__.py

 		self._objects = {}
 		self._joints = {}
 
-		# stores functions to be called on each step of a specific frame.
-		# 	e.g. addTorque
+		# storage of functions to be called on each step of a specific frame
+		# e.g. addTorque
 		self.all_frame_steps_callbacks = []
 
 		self.coll_engine = coll.OdeEngine()
 		time_step = self.time_step
 
 		for i in range(self._STEPS_PF):
-
 			# before each integration step of the physics engine
 			try:
 				# send the signal so subscribers do their stuff in time
 				dispatcher.send(signals.SIM_PRE_STEP, sender=self)
-				# call all registered functions before each step of the next frame
+				# call all registered functions before each step in next frame
 				for callback_ in self.all_frame_steps_callbacks:
 					callback_()
 			except Exception as e:
 			coll_args = coll.NearCallbackArgs(self._world, self._contact_group)
 			self._space.collide(coll_args)
 
-			# step world sim
+			# step physics world simulation
 			self._world.step(time_step)
 			self._sim_time += time_step
 			self.num_iter += 1
 
-			# Remove all contact joints
+			# remove all contact joints
 			self._contact_group.empty()
 
 			# after each integration step of the physics engine
 				print(e)
 
 	def update_actors(self):
-		"""Update the position and rotation of each simulated object's
-		corresponding actor"""
+		"""Update pose of each simulated object's corresponding actor."""
 		for key_ in self._objects:
 			try:
 				if self._objects[key_].is_updatable():
 					self._objects[key_].update_actor()
-
 			except (ValueError, AttributeError) as err:
 				print(err)
 
 
 	@property
 	def actors(self):
-		"""Returns a dictionary with each object actor indexed by its name"""
+		"""Return a dict with each object actor indexed by the object name."""
 		actors = {}
 		for key_ in self._objects:
 			actor = self._objects[key_].actor
 
 	def get_bodies(self):
 		"""Return a list with all the bodies included in the simulation.
-		
+
 		:return: list of :class:`SimulatedBody` objects
-		
+
 		"""
 		bodies = []
 		for key, obj in self._objects.iteritems():
 			# Not all objects are SimulatedBody instances wrapping
-			# a physical instance. That's why we check ``obj.body``.
+			# a physical instance, that's why we check ``obj.body``.
 			try:
 				body = obj.body
 			except AttributeError:
 				body = None
 			if body:
 				# Note that ``obj`` is appended, not ``body`` which was only
-				# retrieved to check it contained a valid physical body.
+				# retrieved to check it contained a valid physical body
 				bodies.append(obj)
 		return bodies
 
 	def add_ball_socket_joint(self, name, obj1, obj2, anchor):
 		"""Adds a "ball and socket" joint between obj1 and obj2, at the
 		specified anchor. If anchor is None, it will be set equal to the
-		position of obj2."""
+		position of obj2.
+
+		"""
 		body1 = obj1.body
 		body2 = obj2.body
 		if not anchor:
 		return self.add_joint(SimulatedJoint(name, bs_joint))
 
 	def add_slider_joint(self, name, obj1, obj2, axis):
-		"""Add a :class:`jo.Slider` joint between obj1 and obj2.
+		"""Add a :class:`jo.Slider` joint between ``obj1`` and ``obj2``.
 
 		The only movement allowed is translation along ``axis``.
 
 		"""Rotate the object by applying a rotation matrix defined by the given
 		axis and angle"""
 		rot_now = mu.matrix_as_3x3_tuples(self.get_rotation())
-		rot_to_apply = mu.matrix_as_3x3_tuples(gemut.calc_rotation_matrix(axis,
-			angle))
-		# Matrix (of the rotation to apply)
-		# multiplies from the LEFT the actual one
-		rot_final = mu.matrix_as_tuple(mu.matrix_multiply(rot_to_apply, rot_now))
+		rot_to_apply = mu.matrix_as_3x3_tuples(
+			gemut.calc_rotation_matrix(axis, angle))
+		# Matrix (of the rotation to apply) multiplies
+		# from the LEFT the actual one
+		rot_final = mu.matrix_as_tuple(
+			mu.matrix_multiply(rot_to_apply, rot_now))
 		self.set_rotation(rot_final)
 
 	def offset_by_position(self, offset_pos):
 	instantiate	abstract class SimulatedBody with abstract methods".
 
 	"""
+
 	def __init__(self, name, body=None, actor=None, geom=None):
 		super(SimulatedBody, self).__init__(name, actor)
 		self._body = body
 		field or method) in this class.
 
 		.. seealso::
-		  http://docs.python.org/reference/datamodel.html#object.__getattr__
+		   http://docs.python.org/reference/datamodel.html#object.__getattr__
+
 		"""
 		return self._get_attr_in_body(attr, *args)