Commits

German Larrain committed c667199 Merge

Merge with dev

Comments (0)

Files changed (3)

ars/app/__init__.py

 	-call its 'start' method (i.e. sim_program.start() )
 
 	"""
-	WRITE_DATA_FILES = False
 	DEBUG = False
 	PRINT_KEY_INFO = True
 
 
 		"""
 		self.do_create_window = True
-		self.data_files_names = None 	# TODO
-		self.data_files = None 			# TODO
 
 		self.key_press_functions = None
 		self.sim = None
 		restart if :attr:`do_create_window` has been previously set to ``True``.
 
 		"""
-		if self.WRITE_DATA_FILES:
-			self.sim.data_files = self.open_files()
-
 		while self.do_create_window:
 			self.do_create_window = False
 			self.gAdapter.start_window(self.sim.on_idle, self.reset_simulation,
 				self.on_action_selection)
 
-		# after the window is closed
-		if self.WRITE_DATA_FILES:
-			self.close_files(self.sim.data_files)
-
 	def reset_simulation(self):
 		"""Resets the simulation by resetting the graphics adapter and creating
 		a new simulation.
 		"""
 		# TODO: add to constructor ``self.key_press_functions = None``?
 		self.key_press_functions = ActionMap()
-		self.key_press_functions.add('plus', self.select_next_joint)
-		self.key_press_functions.add('minus', self.select_previous_joint)
 		self.key_press_functions.add('r', self.reset_simulation)
-		self.key_press_functions.add('h', self.add_force)
-		self.key_press_functions.add('n', self.add_torque)
-		self.key_press_functions.add('f', self.inc_joint_vel)
-		self.key_press_functions.add('v', self.dec_joint_vel)
-		self.key_press_functions.add('g', self.inc_joint_pos)
-		self.key_press_functions.add('b', self.dec_joint_pos)
 
 	def on_action_selection(self, key):
 		"""Method called after an actions is selected by pressing a key."""
 			print(ex)
 
 	#==========================================================================
-	# KEYPRESS action functions
-	#==========================================================================
-
-	def select_next_joint(self):
-		"""select next joint for future user actions"""
-		print('select_next_joint has not been implemented yet')
-
-	def select_previous_joint(self):
-		"""select previous joint for future user actions"""
-		print('select_previous_joint has not been implemented yet')
-
-	def add_force(self):
-		"""add force to an already selected joint"""
-		print('add_force has not been implemented yet')
-
-	def add_torque(self):
-		"""add torque to an already selected joint"""
-		print('add_torque has not been fully implemented')
-
-	def inc_joint_vel(self):
-		"""increment the velocity of an already selected joint"""
-		print('inc_joint_vel has not been implemented yet')
-
-	def dec_joint_vel(self):
-		"""decrement the velocity of an already selected joint"""
-		print('dec_joint_vel has not been implemented yet')
-
-	def inc_joint_pos(self):
-		"""increment the position of an already selected joint"""
-		print('inc_joint_pos has not been implemented yet')
-
-	def dec_joint_pos(self):
-		"""decrement the position of an already selected joint"""
-		print('dec_joint_pos has not been implemented yet')
-
-	#==========================================================================
-	# FILES methods
-	#==========================================================================
-
-	def read_filenames(self):
-		print('read_filenames has not been implemented')
-
-	def open_files(self):
-		print('open_files has not been implemented')
-
-	def close_files(self, files):
-		# TODO
-		for _key in files:
-			files[_key].close()
-
-	#==========================================================================
 	# other
 	#==========================================================================
 
 
 	def __str__(self):
 		raise NotImplementedError()
-
-
-class KeyPressActionMap(ActionMap):
-	"""Customize the behavior, knowing which strings mean existing keys or not,
-	plus combinations (e.g. Ctrl+F1)
-
-	"""
-	pass

ars/model/robot/joints.py

-
-# Created on 2011.10.31
-#
-# @author: german
-
 from abc import ABCMeta, abstractmethod
 
 import ode
 
 import ars.exceptions as exc
 
+
 class Joint:
-	"""
-	Abstract class. Not coupled (at all) with ODE or any other collision library/engine
+	"""Abstract class. Not coupled (at all) with ODE or any other collision
+	library/engine.
+
 	"""
 	__metaclass__ = ABCMeta
 
 	"""
 	__metaclass__ = ABCMeta
 
-	@abstractmethod
-	def get_instant_power(self):
-		"""Calculate and return the power applied by the actuator at the
-		moment.
-
-		"""
-		pass
-
 
 class Fixed(Joint):
 	def __init__(self, world, body1, body2):
 		except:
 			raise exc.PhysicsObjectCreationError(type='Fixed joint')
 
-class Piston(Joint):
-	pass
 
 class Rotary(ActuatedJoint):
 	def __init__(self, world, body1, body2, anchor, axis):
 			inner_joint = ode.HingeJoint(world._inner_object)
 			inner_joint.attach(body1.inner_object, body2.inner_object)
 			inner_joint.setAnchor(anchor)
-			inner_joint.setAxis(axis) # see contrib.Ragdoll.addHingeJoint for possible modification
+			# TODO: see contrib.Ragdoll.addHingeJoint for possible modification
+			inner_joint.setAxis(axis)
 
 			# TODO: necessary?
 			lo_stop = -ode.Infinity
 		except:
 			raise exc.JointError(self, 'Failed to add torque to this joint')
 
-	def get_instant_power(self):
-		""" """
-#		self.body1.get_linear_velocity()
-#		self.body1.get_angular_velocity()
-#
-#		self.body1._inner_object.getTorque()  # current accumulated torque
-#		self.body1._inner_object.getForce()  # current accumulated force
-#
-#		return None
-		raise NotImplementedError()
-
 	@property
 	def angle(self):
 		"""Returns the angle (float) between the two bodies. Its value is
 			self._inner_joint.setParam(ode.ParamFMax, max_force)
 		self._inner_joint.setParam(ode.ParamVel, speed)
 
-class Caster(Joint):
-	pass
 
 class Universal(Joint):
 	def __init__(self, world, body1, body2, anchor, axis1, axis2):
 			inner_joint = ode.UniversalJoint(world._inner_object)
 			inner_joint.attach(body1.inner_object, body2.inner_object)
 			inner_joint.setAnchor(anchor)
-			inner_joint.setAxis1(axis1) # see contrib.Ragdoll.addHingeJoint for possible modification
+			# TODO: see contrib.Ragdoll.addHingeJoint for possible modification
+			inner_joint.setAxis1(axis1)
 			inner_joint.setAxis2(axis2)
 
 			# TODO: necessary?
 		except:
 			raise exc.PhysicsObjectCreationError(type='Universal joint')
 
+
 class BallSocket(Joint):
 	def __init__(self, world, body1, body2, anchor):
 
 		except:
 			raise exc.PhysicsObjectCreationError(type='Ball and Socket joint')
 
-class Wheel(Joint):
-	pass
-
-class Slider(Joint):
-	pass
-
-class Contact(Joint):
-	pass
-
-class JointCollection:
-
-	# TODO: allow true duplicated? weak-duplicated (same bodies, different joint)? variables for that?
-
-	def __init__(self):
-		self._coll = []
-
-	def exists(self, body1, body2):
-		raise NotImplementedError()
-
-	def count(self):
-		return len(self._coll)
-
-	def add_joint(self, joint, warn=True):
-		#noinspection PySimplifyBooleanCheck
-		if self._coll.count(joint) == 0:
-			self._coll.append(joint)
-		elif warn:
-			raise exc.ArsError('Joint is already stored')
 
 class JointFeedback:
-	def __init__(self, body1, body2, force1=None, force2=None, torque1=None, torque2=None):
+	def __init__(self, body1, body2, force1=None, force2=None, torque1=None,
+			torque2=None):
 		self._body1 = body1
 		self._body2 = body2
 		self.force1 = force1
 	@property
 	def body2(self):
 		return self._body2
-
-class ContactGroup:
-
-	def __init__(self):
-		self._contacts = []
-
-	def add(self, contact):
-		raise NotImplementedError()
-
-	def remove(self, contact):
-		raise NotImplementedError()
-
-	def clear(self):
-		raise NotImplementedError()
-
-	def count(self):
-		raise NotImplementedError()

ars/model/simulator/__init__.py

 
 		self._debug = do_debug
 		self._objects = {}
-		#self._joints = jo.JointCollection()
 		self._joints = {}
 
 		# stores functions to be called on each step of a specific frame.
 			print(self.sim_time)
 		self.update_actors()
 
-	def toggle_pause(self):
-		# TODO: use this
-		self.paused = not self.paused
-
 	def perform_sim_steps_per_frame(self):
 
 		time_step = self.time_step
 			self.sim_time += time_step
 			self.num_iter += 1
 
-			# TODO: when "complex" objects are present, "update" them here
-
 			# Remove all contact joints
 			self._contact_group.empty()
 
 		self._joints[name] = sim_joint
 		return name
 
+	@property
+	def objects(self):
+		return self._objects
+
 	def get_object(self, name):
 		return self._objects[name]
 
+	@property
+	def joints(self):
+		return self._joints
+
 	def get_joint(self, name):
 		return self._joints[name]
 
+	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``.
+			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.
+				bodies.append(obj)
+		return bodies
+
 	#==========================================================================
 	# Add joints
 	#==========================================================================
 	# Dynamic and kinematic interaction
 	#==========================================================================
 
-	def add_force(self):
-		raise NotImplementedError()
-
 	def add_torque(self, torque):
 		try:
 			self._joint.add_torque(torque)
 		except Exception as ex:
 			print(ex)
 
-	def inc_velocity(self):
-		raise NotImplementedError()
-
-	def dec_velocity(self):
-		raise NotImplementedError()
-
-	def inc_position(self):
-		raise NotImplementedError()
-
-	def dec_position(self):
-		raise NotImplementedError()
-
 	#==========================================================================
 	# Getters and setters
 	#==========================================================================
 		return self._joint
 
 	def get_position(self):
+		# It is necessary to have this method, even if it's not implemented
 		raise NotImplementedError()
 
 	def set_position(self, position):
+		# It is necessary to have this method, even if it's not implemented
 		raise NotImplementedError()
 
 	def get_rotation(self):
+		# It is necessary to have this method, even if it's not implemented
 		raise NotImplementedError()
 
 	def set_rotation(self, rot_matrix):
+		# It is necessary to have this method, even if it's not implemented
 		raise NotImplementedError()
-
-
-class ActiveObject:
-
-	def __init__(self):
-		self._objects = {}
-		self._joints = jo.JointCollection()
-
-	def update_internal_forces(self):
-		pass
-
-
-class CompositeObject:
-	pass
-
-
-class Environment:
-	pass