Force Sensor

force.py

Overview

force.py is a synthetic end-effector force sensor that publishes pseudo-random force readings so that grasp controllers, compliant planners, and safety monitors can be developed and tested without real hardware.

Interfaces (strongly-typed, stateless)

Direction

Topic

Semantics

Provided

/{robot}/force

std_msgs/Float32 – simulated contact force in Newtons

Contract

Pre-conditions

  • Node launched with a valid robot_id CLI argument.

  • Downstream nodes subscribe to /force at ~10 Hz.

Post-conditions

  • Publishes one Float32 message per loop iteration.

  • data field is a float uniformly drawn from [0, _MAX_FORCE].

Invariants

  • Loop frequency = _RATE ± ROS scheduler jitter.

  • Force range fixed by _MAX_FORCE.

Quality-of-Service KPIs

Metric

Target

Rationale

Message rate

10 Hz ± 0.5 Hz

Ensures smooth controller input.

Latency

< 100 ms

Prevents stale force readings.

CPU load

< 1 %

Safe on embedded CPUs.

Implementation notes

  • Uses random.uniform(0, _MAX_FORCE) for force generation.

  • All logic in force_sensor(); the loop maintains timing.

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

force.force_sensor() None[source]

Initialise ROS publisher and broadcast random force values until shutdown.

Workflow

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

  2. Advertise /robot/force (Float32, queue_size=10).

  3. Loop at _RATE Hz:

    1. Generate f = uniform(0, _MAX_FORCE).

    2. Publish Float32(f).

    3. Sleep to maintain rate.