Camera
camera.py
Overview
camera.py is a horizontal sensor-stub component: a self-contained software camera that produces deterministic RGB + depth imagery even when no physical sensor is present. It lets downstream perception, fusion and visualisation nodes run in CI, headless simulation, or early prototyping environments where real hardware is unavailable.
Interfaces (strongly-typed, stateless)
Direction |
Topic |
Message type |
Notes |
---|---|---|---|
Provided |
|
|
Static BGR8 frame read from image.jpg |
Provided |
|
|
8-bit signed mono array (ones); same resolution as RGB |
Both topics share identical header.stamp
values and are published at
10 Hz, allowing time-synchronisation filters to treat them as a stereo pair.
Contract
Pre-conditions
The JPEG file exists and is readable.
Resolution ≤ 1920 × 1080 (soft real-time ceiling).
Post-conditions
The depth image’s height and width match the RGB frame exactly.
Header fields
stamp
andframe_id
are identical between colour and depth messages.
Invariants
Latency (JPEG load → publish) ≤ 8 ms on a 4-core laptop.
Peak RAM ≤ 2 × (W × H × 3) bytes (one colour buffer + one depth buffer).
Protocol
This component is stateless: each 100 ms cycle publishes fresh, independent messages.
Lifecycle
Node name
{robot}_camera
Ready once its publishers are advertised (no init service).
Clean shutdown on Ctrl-C or
rosnode kill
.
Quality & Reusability metrics
Latency < 8 ms | Throughput = 10 Hz | Cyclomatic complexity < 10
Directory layout
camera.py
expects the JPEG at
/root/Desktop/cogar_ass1/cogar_ws/src/tiago1/scripts/image.jpg
Update the path if you move the file; no other configuration is required.
- camera.publish()[source]
Bootstrap the node and stream frames until ROS shuts down.
Execution flow
Node init – registers with the ROS master under
{robot}_camera
.Publisher creation •
pub_rgb
→/{robot}/camera
(BGR8 colour) •pub_depth
→/{robot}/depth
(8-bit signed mono)Main loop (10 Hz) a. Load the static JPEG each cycle (immediate visual edits propagate). b. Convert to
sensor_msgs/Image
via cv_bridge and publish. c. Allocate a matching depth array filled with ones, convert andpublish.
Sleep the remainder of the 100 ms period.
Loop exits cleanly when
rospy.is_shutdown()
becomes True.
Exceptions
Any non-ROS exception aborts the node and prints a traceback, which is useful during development. ROS interruptions are swallowed in main.