Commits

German Larrain  committed 005f3c6

new experiment (#2) for the RSS conference paper, which uses the trimesh floor experimental feature

  • Participants
  • Parent commits 9c20ae2
  • Branches trimesh-floor

Comments (0)

Files changed (1)

+#!/usr/bin/env python
+
+# Created on 2012.01.16
+#
+# @author: german
+
+# TODO: deal with license of "get_faces" code
+
+"""
+Experiment #2 for a paper submitted to the 
+2012 Robotics Science and Systems conference
+"""
+
+import sys
+from random import random, choice
+
+from ars.model.simulator import Simulation
+from ars.model.geometry.shapes import Trimesh
+from Vehicle2 import Vehicle2
+
+def random_heightfield(num_x, num_z, scale=1.0):
+	"""
+	Copied from:
+		Edward Dale - Snowballs: An experiment in Winter frivolity (2006).
+		http://scompt.com/files/cg2/final.pdf
+		
+	A height field where values are completely random.
+	"""
+	verts=[]
+	for x in range(num_x):
+		for z in range(num_z):
+			verts.append( (x, random()*scale, z) )
+	return verts
+
+def shrink_XZ_heightfield(vertices, factor=(1.0,1.0)):
+	
+	new_vertices = []
+	for vertex in vertices:
+		new_vertices.append((vertex[0]/factor[0], vertex[1], vertex[2]/factor[1]))
+	return new_vertices
+
+class RSS2(Vehicle2):
+	
+	STEPS_PER_FRAME = 1000
+	
+	def __init__(self):
+		""" Constructor, calls first the superclass constructor. """
+		Vehicle2.__init__(self)
+	
+	def create_simulation(self):
+		
+		tm_resolution = 1.0
+		tm_x, tm_z = (20,20)
+		shrink_factor = (1.0,1.0)
+		vertices = random_heightfield(tm_x, tm_z, 0.5)
+		vertices = shrink_XZ_heightfield(vertices, shrink_factor)
+		faces = Trimesh.get_faces(int(tm_resolution) * tm_x, int(tm_resolution) * tm_z)
+		
+		# set up the simulation parameters
+		self.sim = Simulation(self.FPS, self.STEPS_PER_FRAME)
+		self.sim.add_basic_simulation_objects()
+		self.sim.add_axes()
+		self.sim.add_trimesh_floor(vertices, faces, color=(0.7,0.7,0.7))
+		
+		self.create_sim_objects()
+		
+		# add the graphic objects
+		self.gAdapter.add_objects_list(self.sim.get_actors().values())
+		self.sim.update_actors()
+
+if __name__ == '__main__':
+	a = RSS2()
+	a.start()
+	sys.exit(None)