Commits

German Larrain committed 73c6b7a

demos.sensors: added a usage example of JointPower

Comments (0)

Files changed (1)

demos/sensors/joint_power1.py

+#!/usr/bin/env python
+
+"""Shows usage of the JointPower sensor, with the CentrifugalForce 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 :meth:`create_sim_objects`.
+>>> self.sensor = sen.JointPower(joint_object, self.sim)
+
+It is updated automatically every time torque or force is added to the joint,
+i.e. each call to ``joint.add_torque`` or ``joint.add_force``.
+
+Sensor measurements can be easily retrieved at any time
+>>> self.sensor.data_queue.pull()
+
+"""
+import ars.model.robot.sensors as sen
+
+from base import CentrifugalForce
+
+
+class JointPower(CentrifugalForce):
+
+	def create_sim_objects(self):
+		CentrifugalForce.create_sim_objects(self)
+		joint_object = self.sim.get_joint('r2')
+		self.sensor = sen.JointPower(joint_object, self.sim)
+
+if __name__ == '__main__':
+	sim_program = JointPower()
+	sim_program.start()
+
+	sensor = sim_program.sensor
+	print('sensor data queue count %d' % sensor.data_queue.count())
+	print(sensor.data_queue)