Source

ars / demos / sensors / joint_torque1.py

#!/usr/bin/env python

"""Shows usage of the JointTorque 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.JointTorque(joint_object, self.sim)

It is updated automatically every time torque is added to the joint, i.e.
each time ``joint.addTorque(x)`` is called.

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 JointTorque(CentrifugalForce):

	def create_sim_objects(self):
		CentrifugalForce.create_sim_objects(self)
		joint_object = self.sim.get_joint('r2')
		self.sensor = sen.JointTorque(joint_object, self.sim)

if __name__ == '__main__':
	sim_program = JointTorque()
	sim_program.start()

	sensor = sim_program.sensor
	print('sensor data queue count %d' % sensor.data_queue.count())
	print(sensor.data_queue)