# Advancing Road Infrastructure Safety with the Remotely Piloted Safety Cone
## 2 Materials and Methods
### Software Architecture  
The Raspberry Pi runs Ubuntu Server 24.04 and ROS2 Jazzy. By using the server version, the graphical interface is removed, dedicating processing capacity to essential algorithms for the RPSC. ROS2 Jazzy provides a modular framework for efficient node management, ensuring interoperability among the RPSC subsystems. The architecture is based on distributed ROS2 nodes, ensuring scalability and robustness. The key nodes are as follows:MAVROS Node: As the primary interface between ROS2 and the Pixhawk, utilising the MAVLink v2 protocol via the serial port /dev/ttyS0, configured at 57,600 bps. It handles critical data, publishing topics such as /RPSC/local_position/pose for local pose, /RPSC/global_position/global for global GNSS position, and /RPSC/state for system status, while subscribing to /RPSC/setpoint_velocity/cmd_vel to send velocity commands. This node ensures smooth, bidirectional communication, integrating the Pixhawk with the ROS2 ecosystem. Visual Alarm Node: This node controls relays connected to the Raspberry Pi's GPIO pins to activate high-intensity visual signals in critical situations. It receives commands from the control station or the Pixhawk via the /RPSC/visual_alarm_cmd topic, triggering immediate alerts to warn workers and road users. This node operates with high priority to guarantee a rapid response. Obstacle Detection Node: This node processes data from the HC-SR04 ultrasonic sensor connected to the Raspberry Pi, generating local obstacle maps in LaserScan format and publishing them on /RPSC/obstacle_scan. This data is converted to DISTANCE_SENSOR messages using pymavlink and sent to the Pixhawk via MAVROS. This node enables the Pixhawk to dynamically adjust paths, integrating with the reactive navigation system. RTK Injector Node: This node functions as an NTRIP client, receiving real-time RTCM corrections from an RTK base station. It processes these corrections and sends them to the Pixhawk via the /RPSC/send_rtcm topic, improving the Here3+'s GNSS positioning accuracy. This node ensures that the RPSC maintains centimetre-level accuracy, which is crucial for navigating constrained road environments. Heartbeat Node: This node monitors communication with the control station, checking the heartbeat every 0.5 s. If a disruption is detected, it triggers an emergency protocol that sends a command to the /RPSC/set_mode topic to switch to HOLD mode, disarms the motors, and activates the visual alarms via the corresponding node. This node complements Pixhawk's LUA script, providing an additional safety layer. Autonomous Motion Node: This node receives velocity information via the /RPSC/setpoint_velocity/cmd_vel topic, which contains linear and angular velocities. The Pixhawk receives these commands and adjusts its route to match the specified speed. It can also recalculate its route if the obstacle detection node detects an object in the RPSC's path. Wi-Fi Mapping Node: This node uses the Wi-Fi module to log the real-time quality of Wi-Fi coverage. It processes data from /RPSC/global_position/global and /RPSC/gps_status topics (Horizontal Dilution of Precision (HDOP) and Vertical Dilution of Precision (VDOP)), generating logs that include global position, altitude, and Wi-Fi signal quality. The data are stored as ROS2 bags for later analysis, allowing evaluation of communication quality during RPSC operations. The RPSC lifecycle is implemented as an ROS2 node called rpsc_lifecycle_node. Unlike previous nodes that added specific functionalities, this node is responsible for managing the operational states of the system and coordinating transitions between them. The lifecycle includes the following states: INITIALIZING, WAITING RTK, INITIALIZED, FOLLOWING, MANUAL, and ALERTING. Transitions between these states are based on initialisation conditions, GNSS quality, mode commands, and failsafe or alarm events. The state machine, which is designed to coordinate the safe operation of the RPSC and outline its functionality, is presented in the pseudocode below (Algorithm 1).