Commits

German Larrain committed e248545

model.robot.sensors: new class 'PotentialEnergy'

  • Participants
  • Parent commits d03b7e7
  • Branches dev-sensors

Comments (0)

Files changed (1)

File ars/model/robot/sensors.py

 			'rotation energy': self.body.calc_rotation_kinetic_energy(), }
 		return SensorData(**kwargs)
 
+
+class PotentialEnergy(BodySensor):
+	r"""Calculate and retrieve body's potential energy based on the current
+	position (`x`) and world's gravitational acceleration (`g`).
+
+	.. math::
+		E_p = m \cdot g \cdot h = - m \cdot g^\top x
+
+	"""
+	def __init__(self, body, gravity):
+		super(PotentialEnergy, self).__init__(body)
+		self._gravity = gravity
+	
+	def _build_data(self):
+		potential_e = self.body.calc_potential_energy(self._gravity)
+		kwargs = {'potential energy': potential_e, }
+		return SensorData(**kwargs)
+
 #==============================================================================
 # aux classes
 #==============================================================================