Service Management Layer
Overview
Section titled “Overview”lite3_sdk_service is a UDP-based remote control service responsible for managing the start/stop and configuration of the lite3_transfer node.
Node Information
Section titled “Node Information”# ros2 node info /lite3_sdk_service/lite3_sdk_service Service Clients: /EMERGENCY_STOP: drdds/srv/StdSrvInt32 /SDK_MODE: drdds/srv/StdSrvInt32UDP Control Commands
Section titled “UDP Control Commands”The service listens on UDP port 12122 and supports the following commands:
Start/Stop Transfer Node
Section titled “Start/Stop Transfer Node”on # Start lite3_transferoff # Stop lite3_transferResponse: success or failure
Set Publish Frequency
Section titled “Set Publish Frequency”<number> # e.g., 50, 100, 200Response: success, failure, or invalid
Valid values: Must be > 0, <= 200, and a factor of 200 (e.g., 1, 2, 4, 5, 8, 10, 20, 25, 40, 50, 100, 125, 200)
Emergency Stop
Section titled “Emergency Stop”estopResponse: success or failure
Service Interface
Section titled “Service Interface”SdkService is a pure virtual base class:
virtual void Initialize(rclcpp::Node::SharedPtr node) = 0;virtual bool StartNode() = 0;virtual bool StopNode() = 0;virtual bool SetPublishRate(int32_t rate) = 0;virtual std::string ProcessCommand(const std::string& cmd) = 0;virtual bool InitializeUdp(int port) = 0;virtual void RunUdpLoop() = 0;virtual void Cleanup() = 0;Node Start Flow (StartNode)
Section titled “Node Start Flow (StartNode)”lite3_pid_ = fork();if (lite3_pid_ == 0) { setpgid(0, 0); // Set process group execlp("ros2", "ros2", "run", "lite3_transfer", "lite3_transfer", nullptr);}Creates a child process via fork(), and the child process uses execlp to execute ros2 run lite3_transfer lite3_transfer.
Node Stop Flow (StopNode)
Section titled “Node Stop Flow (StopNode)”Graceful stop is a three-step process:
- Call
/SDK_MODEservice with command0to exit SDK mode (wait 2s timeout) - Send
SIGINTto the child process group - Wait 2s; if not exited, send
SIGKILLto force termination
Command Processing
Section titled “Command Processing”| Command | Action |
|---|---|
on | Call StartNode() |
off | Call StopNode() |
estop | Call SendEmergencyStop() |
| Number | Call SetPublishRate(rate) |
| Other | Return invalid |
Service Deployment
Section titled “Service Deployment”One-Click Deployment Script
Section titled “One-Click Deployment Script”cd ~/sdk_service/src/lite3_sdk_servicechmod +x setup_service.sh./setup_service.shOptional parameters:
./setup_service.sh -r foxy -d 0-r <distro>: ROS2 distribution, defaultfoxy-d <domain>:ROS_DOMAIN_ID, default0
Script execution flow:
- Environment check (ROS2, colcon, source packages)
colcon build --packages-up-to lite3_sdk_service- Create
/etc/systemd/system/lite3_sdk_service.service systemctl enableandsystemctl restart
Manual Build
Section titled “Manual Build”cd ~/sdk_servicesource /opt/ros/foxy/setup.bashcolcon build --packages-up-to lite3_sdk_service
# Test runsource install/setup.bashros2 run lite3_sdk_service sdk_serviceSystemd Configuration
Section titled “Systemd Configuration”[Unit]Description=Lite3 SDK Control ServiceAfter=network.target
[Service]Type=simpleUser=yscEnvironment=ROS_DOMAIN_ID=0ExecStart=/bin/bash -lc 'source /opt/ros/foxy/setup.bash && \ source /home/ysc/sdk_service/install/setup.bash && \ exec ros2 run lite3_sdk_service sdk_service'Restart=on-failure
[Install]WantedBy=multi-user.targetService Management
Section titled “Service Management”sudo systemctl daemon-reloadsudo systemctl enable lite3_sdk_servicesudo systemctl start lite3_sdk_servicesudo systemctl status lite3_sdk_serviceNode Lifecycle Management
Section titled “Node Lifecycle Management”lite3_transfer is not a standalone systemd service; it is started and stopped on demand by lite3_sdk_service:
lite3_sdk_servicestarts on boot- On receiving
oncommand, forks and startslite3_transfer - On receiving
offcommand, gracefully exits SDK mode first, then SIGINT/SIGKILL
Event Tracing (sdk_service_trace)
Section titled “Event Tracing (sdk_service_trace)”Controlled via config/trace.yaml configuration file:
enable: true # Master switchconsole: true # Console outputfile: true # File outputsdk_service_trace: true # Service layer trace switchlog_dir: "" # Log directory (default ~/ros2 debug log)Log files are created per session, with path format:
<log_dir>/<YYYYMMDD_HHMMSS>_<process_tag>_pid<PID>/SDK_SERVICE_EVENT_<stamp>.log