1. German Larrain
  2. ars


ars / demos / sensors / total_energy1.py

"""Shows usage of the TotalEnergy sensor, with the FallingBalls program.
Sensor data is stored in a queue, which is retrieved after the simulation ends
(but it can be accessed at any time).

Sensor is created in the `create_sim_objects` method.
	'self.sensor = sensors.TotalEnergy(ball_object, self.sim.gravity)'
It is updated in the `on_post_step` method
Sensor measurements can be retrieved at any time

from ars.app import dispatcher
from ars.model.robot import sensors
from ars.model.simulator import signals

from .base import FallingBalls, PrintDataMixin, logger

class TotalEnergy(FallingBalls, PrintDataMixin):

	def __init__(self):
		dispatcher.connect(self.on_post_step, signals.SIM_POST_STEP)

	def create_sim_objects(self):
		ball_object = self.sim.get_object(self.ball1)
		self.sensor = sensors.TotalEnergy(ball_object, self.sim.gravity)
		# self.sensor = sensors.TotalEnergy(ball_object, self.sim.gravity, True)

	def on_post_step(self):
			time = self.sim.sim_time
		except Exception:
			logger.exception("Exception when executing on_post_step")