encoder_gripper

encoder_gripper.py

Overview

encoder_gripper.py is a dummy gripper-position sensor that publishes pseudo-random gripper opening widths at a fixed rate. It enables PID loops, dashboards and loggers to run when the physical gripper is offline or during CI.

Interfaces (strongly-typed, stateless)

Direction

Topic

Semantics

Provided

/{robot}/encoder_gripper

std_msgs/Int32 – simulated gripper opening width in mm (0–100)

Contract

Pre-conditions

  • Node launched with a valid robot_id CLI argument.

  • Subscribers expect gripper widths at ~10 Hz.

Post-conditions

  • Publishes exactly one Int32 per loop iteration.

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

  • No internal state retained beyond the RNG.

Invariants

  • Loop frequency = _RATE ± ROS scheduler jitter.

  • Width range fixed by _MAX_WIDTH.

Quality-of-Service KPIs

Metric

Target

Rationale

Message rate

10 Hz ± 0.5 Hz

Keeps gripper controllers in sync.

Latency

< 100 ms

Prevents stale position readings.

CPU load

< 1 %

Safe on embedded CPU.

Implementation notes

  • Uses random.randint(0, _MAX_WIDTH) for uniform width generation.

  • All logic is in gripper_encoder(); the main loop maintains timing.

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

Functions

gripper_encoder()

Initialise ROS publisher and broadcast random gripper widths until shutdown.