Encoder Arm

encoder_arm.py

Overview

encoder_arm.py is a synthetic joint-position sensor that publishes pseudo-random encoder angles for the TIAGo arm at a fixed rate. It enables controllers, loggers, and dashboards to run when no real hardware is connected.

Interfaces (strongly-typed, stateless)

Direction

Topic

Semantics

Provided

/{robot}/encoder_arm

std_msgs/Int32 – simulated joint angle in degrees [0–359]

Contract

Pre-conditions

  • Node launched with a valid robot_id CLI argument.

  • Downstream subscribers expect arm encoder ticks at ~10 Hz.

Post-conditions

  • Publishes exactly one Int32 per loop iteration.

  • data field is an integer uniformly drawn from [0, _MAX_ANGLE].

  • No other side-effects or retained state.

Invariants

  • Loop frequency = _RATE Hz ± ROS scheduler jitter.

  • Angle range fixed by _MAX_ANGLE.

Quality-of-Service KPIs

Metric

Target

Rationale

Message rate

10 Hz ± 0.5 Hz

Keeps controllers in sync.

Latency

< 100 ms

Prevents stale joint readings.

CPU load

< 1 %

Safe on onboard CPU.

Implementation notes

  • Uses random.randint(0, _MAX_ANGLE) for angle generation.

  • All logic resides in arm_encoder(); the main loop only maintains timing.

  • Seed the RNG (random.seed(…)) before calling for reproducible traces.

encoder_arm.arm_encoder() None[source]

Initialise ROS publisher and broadcast random encoder angles until shutdown.

Workflow

  1. Read robot_id from CLI and initialise node <robot>_encoder_arm>.

  2. Advertise /robot/encoder_arm (queue_size=10).

  3. Loop at _RATE Hz:

    1. Generate angle = randint(0, _MAX_ANGLE).

    2. Publish Int32(angle).

    3. Sleep to maintain rate.