Skip to content

Service Management Layer

lite3_sdk_service is a UDP-based remote control service responsible for managing the start/stop and configuration of the lite3_transfer node.

Terminal window
# ros2 node info /lite3_sdk_service
/lite3_sdk_service
Service Clients:
/EMERGENCY_STOP: drdds/srv/StdSrvInt32
/SDK_MODE: drdds/srv/StdSrvInt32

The service listens on UDP port 12122 and supports the following commands:

on # Start lite3_transfer
off # Stop lite3_transfer

Response: success or failure

<number> # e.g., 50, 100, 200

Response: 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)

estop

Response: success or failure

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;
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.

Graceful stop is a three-step process:

  1. Call /SDK_MODE service with command 0 to exit SDK mode (wait 2s timeout)
  2. Send SIGINT to the child process group
  3. Wait 2s; if not exited, send SIGKILL to force termination
CommandAction
onCall StartNode()
offCall StopNode()
estopCall SendEmergencyStop()
NumberCall SetPublishRate(rate)
OtherReturn invalid
Terminal window
cd ~/sdk_service/src/lite3_sdk_service
chmod +x setup_service.sh
./setup_service.sh

Optional parameters:

Terminal window
./setup_service.sh -r foxy -d 0
  • -r <distro>: ROS2 distribution, default foxy
  • -d <domain>: ROS_DOMAIN_ID, default 0

Script execution flow:

  1. Environment check (ROS2, colcon, source packages)
  2. colcon build --packages-up-to lite3_sdk_service
  3. Create /etc/systemd/system/lite3_sdk_service.service
  4. systemctl enable and systemctl restart
Terminal window
cd ~/sdk_service
source /opt/ros/foxy/setup.bash
colcon build --packages-up-to lite3_sdk_service
# Test run
source install/setup.bash
ros2 run lite3_sdk_service sdk_service
[Unit]
Description=Lite3 SDK Control Service
After=network.target
[Service]
Type=simple
User=ysc
Environment=ROS_DOMAIN_ID=0
ExecStart=/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.target
Terminal window
sudo systemctl daemon-reload
sudo systemctl enable lite3_sdk_service
sudo systemctl start lite3_sdk_service
sudo systemctl status lite3_sdk_service

lite3_transfer is not a standalone systemd service; it is started and stopped on demand by lite3_sdk_service:

  • lite3_sdk_service starts on boot
  • On receiving on command, forks and starts lite3_transfer
  • On receiving off command, gracefully exits SDK mode first, then SIGINT/SIGKILL

Controlled via config/trace.yaml configuration file:

enable: true # Master switch
console: true # Console output
file: true # File output
sdk_service_trace: true # Service layer trace switch
log_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