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 |
|
|
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.
- encoder_gripper.gripper_encoder() None [source]
Initialise ROS publisher and broadcast random gripper widths until shutdown.
Workflow
Read robot_id from CLI and initialise node <robot>_encoder_gripper>.
Advertise /robot/encoder_gripper (queue_size=10).
Loop at _RATE Hz:
Generate width = randint(0, _MAX_WIDTH).
Publish Int32(width).
Sleep to maintain rate.