Commits

German Larrain committed bd64ca7

backport of 640685d90cb2 and 842f6e6c5fc0

Comments (0)

Files changed (1)

ars/model/simulator/__init__.py

-
-# Created on 2011.10.17
-#
-# @author: german
 from abc import ABCMeta, abstractmethod
 
 import random
 
 class Simulation:
 
-	def __init__(self, FPS, STEPS_PF, do_debug = False):
+	def __init__(self, FPS, STEPS_PF, do_debug=False):
 		self._FPS = FPS
 		self._DT = 1.0 / FPS
-		self._STEPS_PF = STEPS_PF # steps per frame
+		self._STEPS_PF = STEPS_PF  # steps per frame
 		self.paused = False
 		self.sim_time = 0.0
 		self.num_iter = 0
 		#self._joints = jo.JointCollection()
 		self._joints = {}
 
-		# stores functions to be called on each step of a specific frame. e.g. addTorque
+		# stores 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): #@UnusedVariable
+		for i in range(self._STEPS_PF):
 
 			# before each integration step of the physics engine
 			try:
 			except Exception as e:
 				print(e)
 
-
 	def update_actors(self):
 		"""Update the position and rotation of each simulated object's
 		corresponding actor"""
 		name = 'axes'
 		return self.add_object(SimulatedObject(name, actor=gAxes))
 
-	def add_floor(self, normal=(0,1,0), dist=0, box_size=(5,0.1,5), box_center=(0,0,0), color=(0.2,0.5,0.5)):
+	def add_floor(self, normal=(0, 1, 0), dist=0, box_size=(5, 0.1, 5),
+			box_center=(0, 0, 0), color=(0.2, 0.5, 0.5)):
 		"""Create a plane geom to simulate a floor. It won't be used explicitly
 		later (space object has a reference to it)"""
-		# FIXME: the relation between ODE's definition of plane and the center of the box
-		self._floor_geom = self.phs_engine.create_plane_geom(self._space, normal, dist)
-		gFloor = gp.Box(box_size, box_center) #TODO: use normal parameter for orientation
+		# FIXME: the relation between ODE's definition of plane and the center
+		# 	of the box
+		self._floor_geom = self.phs_engine.create_plane_geom(self._space,
+			normal, dist)
+		# TODO: use normal parameter for orientation
+		gFloor = gp.Box(box_size, box_center)
 		gFloor.set_color(color)
 		name = "floor"
 		return self.add_object(SimulatedObject(name, actor=gFloor))
 
-	def add_trimesh_floor(self, vertices, faces, center=(0,0,0), color=(0.2,0.5,0.5)):
+	def add_trimesh_floor(self, vertices, faces, center=(0, 0, 0),
+			color=(0.2, 0.5, 0.5)):
 		self._floor_geom = coll.Trimesh(self._space, vertices, faces, center)
 		gFloor = gp.Trimesh(vertices, faces, center)
 		gFloor.set_color(color)
 		body.set_position(center)
 
 		g_box = gp.Box(size, center)
-		name = "box" + str(center) #FIXME
+		name = "box" + str(center)  # FIXME
 		return self.add_object(SimulatedBody(name, body, g_box))
 
 	def add_cylinder(self, length, radius, center, mass=None, density=None):
 	def get_joint(self, name):
 		return self._joints[name]
 
-#===============================================================================
-# ADD JOINTS
-#===============================================================================
+	#==========================================================================
+	# Add joints
+	#==========================================================================
 
 	def add_fixed_joint(self, obj1, obj2):
 		body1 = obj1.body
 		bs_joint = jo.BallSocket(self._world, body1, body2, anchor)
 		return self.add_joint(SimulatedJoint(name, bs_joint))
 
+
 class SimulatedObject:
 	__metaclass__ = ABCMeta
 
 			self._name = str(self)
 		self._actor = actor
 
-	#===========================================================================
-	# GETTERS AND SETTERS
-	#===========================================================================
+	#==========================================================================
+	# Getters and setters
+	#==========================================================================
 
 	def get_name(self):
 		return self._name
 	def is_updatable(self):
 		return self.has_actor() and self._updatable
 
+
 class SimulatedPhysicsObject(SimulatedObject):
 	__metaclass__ = ABCMeta
 
 		"""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))
-		# the rotation matrix to be applied multiplies from the LEFT the actual one
+		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.matrix3_multiply(rot_to_apply, rot_now))
 		self.set_rotation(rot_final)
 
 	def set_rotation(self, rot_matrix):
 		pass
 
+
 class SimulatedBody(SimulatedPhysicsObject):
 
 	def __init__(self, name, body=None, actor=None, geom=None):
 		super(SimulatedBody, self).__init__(name, actor)
 		self._body = body
-		self._geom = geom # we might need it in the future
+		self._geom = geom  # we might need it in the future
 
 	def offset_by_position(self, offset_pos):
 		pos = self._body.get_position()
 	#def has_body(self):
 	#	return not self._body is None
 
-#===============================================================================
-# GETTERS AND SETTERS
-#===============================================================================
+	#==========================================================================
+	# Getters and setters
+	#==========================================================================
 
 	@property
 	def body(self):
 	def offset_by_position(self, offset_pos):
 		raise NotImplementedError()
 
-	#===========================================================================
-	# DYNAMIC AND KINEMATIC INTERACTION
-	#===========================================================================
+	#==========================================================================
+	# Dynamic and kinematic interaction
+	#==========================================================================
 
 	def add_force(self):
 		raise NotImplementedError()
 	def dec_position(self):
 		raise NotImplementedError()
 
-	#===========================================================================
-	# GETTERS AND SETTERS
-	#===========================================================================
+	#==========================================================================
+	# Getters and setters
+	#==========================================================================
 
 	@property
 	def joint(self):
 	def set_rotation(self, rot_matrix):
 		raise NotImplementedError()
 
+
 class ActiveObject:
 
 	def __init__(self):
 	def update_internal_forces(self):
 		pass
 
+
 class CompositeObject:
 	pass
 
+
 class Environment:
 	pass
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.