Skip to content

ROS Topic Test Cases

ROS master-slave communication has been configured (robot dog as master, local computer as slave).

The operation steps in this article use the perception host as an example. The navigation host configuration is similar.

Connect the development host to the robot dog’s rear Ethernet port via cable, or connect via WiFi:

  • WiFi name: X30****** (check the robot dog serial number)
  • WiFi password: 12345678

Connect to WiFi

Terminal window
ssh ysc@192.168.1.105

Password is ' (English single quote)

Login success screen

Test Connectivity Between Local and Robot Dog Terminals

Section titled “Test Connectivity Between Local and Robot Dog Terminals”

Get the local terminal IP:

View local IP

Ping from the robot dog terminal to the local terminal, and from the local terminal to the robot dog terminal:

Terminal window
ping 192.168.1.123 # Enter in robot dog terminal, replace with your local terminal IP
ping 192.168.1.105 # Enter in local terminal

If both terminals receive data, connectivity is confirmed.

Ping test 1

Ping test 2

Terminal window
export HOSTNAME=szc # Replace with your local terminal name
export ROS_IP=192.168.1.123 # Replace with your local terminal IP
export ROS_MASTER_URI=http://192.168.1.105:11311 # Robot dog IP

After modification, run source ~/.bashrc.

Slave bashrc configuration verification

Modify Slave hosts File (usually only needs to be done once)

Section titled “Modify Slave hosts File (usually only needs to be done once)”
Terminal window
sudo vi /etc/hosts

Add the following (note: use tab between IP and hostname, not spaces):

192.168.1.123 szc # Replace with your local terminal IP and name
192.168.1.105 ysc

Slave hosts file modification

Terminal window
export ROS_HOSTNAME=ysc
export ROS_IP=192.168.1.105
export ROS_MASTER_URI=http://192.168.1.105:11311

After modification, run source ~/.bashrc.

Master bashrc configuration verification

Verify output:

Terminal window
http://192.168.1.105:11311
http://192.168.1.105:11311

Master bashrc verification result

Terminal window
sudo vi /etc/hosts

Add the following:

192.168.1.105 ysc
192.168.1.123 szc # Replace with your local terminal IP and name

Master hosts file modification

On the local terminal, execute:

Terminal window
rostopic list

If a list of topic names is displayed:

rostopic list

Test with the /battery/current topic:

Terminal window
rostopic echo /battery/current

If topic messages are received, master-slave communication is configured correctly.

rostopic echo test

Scenario 1: Built-in ROS Topic, No Custom Definition Needed

Section titled “Scenario 1: Built-in ROS Topic, No Custom Definition Needed”

Using the /imu/data topic as an example, which starts publishing immediately after boot.

#include "ros/ros.h"
#include "sensor_msgs/Imu.h"
int g_count = 0;
void imuCallback(const sensor_msgs::Imu::ConstPtr& msg)
{
g_count++;
ROS_INFO("Subscribed imu data, cycle : %d ", g_count);
ROS_INFO("header: ");
ROS_INFO(" seq: %d", msg->header.seq);
ROS_INFO(" stamp: ");
ROS_INFO(" secs: %d", msg->header.stamp.sec);
ROS_INFO(" nsecs: %d", msg->header.stamp.nsec);
ROS_INFO(" frame_id: \"%s\"", msg->header.frame_id.c_str());
ROS_INFO("orientation: ");
ROS_INFO(" x: %f", msg->orientation.x);
ROS_INFO(" y: %f", msg->orientation.y);
ROS_INFO(" z: %f", msg->orientation.z);
ROS_INFO(" w: %f", msg->orientation.w);
ROS_INFO("angular_velocity: ");
ROS_INFO(" x: %f", msg->angular_velocity.x);
ROS_INFO(" y: %f", msg->angular_velocity.y);
ROS_INFO(" z: %f", msg->angular_velocity.z);
ROS_INFO("linear_acceleration: ");
ROS_INFO(" x: %f", msg->linear_acceleration.x);
ROS_INFO(" y: %f", msg->linear_acceleration.y);
ROS_INFO(" z: %f", msg->linear_acceleration.z);
ROS_INFO("---");
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "imu_subscriber");
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe("/imu/data", 10, imuCallback);
ros::spin();
return 0;
}
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
sensor_msgs
)

CMakeLists find_package

catkin_package(
CATKIN_DEPENDS roscpp rospy sensor_msgs
)

CMakeLists catkin_package

add_executable(imu_subscriber src/imu_subscriber.cpp)
target_link_libraries(imu_subscriber ${catkin_LIBRARIES})

CMakeLists add_executable

Terminal window
cd ~/jy_cog/transfer
catkin_make
export ROS_IP=192.168.1.123 # Replace with your local terminal IP
export ROS_MASTER_URI=http://192.168.1.105:11311
source devel/setup.bash
rosrun imu_driver imu_subscriber

Using the /battery_state topic as an example, with message type message_transformer_cpp/BatteryData being a custom message type.

Custom Message File Source (BatteryData.msg)

Section titled “Custom Message File Source (BatteryData.msg)”
uint16 voltage
int16 current
uint16 remaining_capacity
uint16 nominal_capacity
uint16 cycles
uint16 production_date
uint16 balanced_low
uint16 balanced_high
uint16 protected_state
uint8 software_version
uint8 battery_level
uint8 mos_state
uint8 battery_quantity
uint8 battery_ntc
float32[] battery_temperature
#include "ros/ros.h"
#include "battery_state/BatteryData.h"
int g_count = 0;
void batteryCallback(const battery_state::BatteryData::ConstPtr& msg)
{
g_count++;
ROS_INFO("voltage: %d", msg->voltage);
ROS_INFO("current: %d", msg->current);
ROS_INFO("remaining_capacity: %d", msg->remaining_capacity);
ROS_INFO("nominal_capacity: %d", msg->nominal_capacity);
ROS_INFO("cycles: %d", msg->cycles);
ROS_INFO("production_date: %d", msg->production_date);
ROS_INFO("balanced_low: %d", msg->balanced_low);
ROS_INFO("balanced_high: %d", msg->balanced_high);
ROS_INFO("protected_state: %d", msg->protected_state);
ROS_INFO("software_version: %d", msg->software_version);
ROS_INFO("battery_level: %d", msg->battery_level);
ROS_INFO("mos_state: %d", msg->mos_state);
ROS_INFO("battery_quantity: %d", msg->battery_quantity);
ROS_INFO("battery_ntc: %d", msg->battery_ntc);
ROS_INFO("battery_temperature: [");
for (size_t i = 0; i < msg->battery_temperature.size(); ++i) {
if (i == msg->battery_temperature.size() - 1) {
ROS_INFO(" %f", msg->battery_temperature[i]);
} else {
ROS_INFO(" %f,", msg->battery_temperature[i]);
}
}
ROS_INFO("]");
ROS_INFO("---");
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "battery_subscriber");
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe("/battery_state", 10, batteryCallback);
ros::spin();
return 0;
}
find_package(catkin REQUIRED COMPONENTS
geometry_msgs
roscpp
rospy
std_msgs
message_generation
)
add_message_files(FILES BatteryData.msg)
generate_messages(DEPENDENCIES std_msgs)
catkin_package(
CATKIN_DEPENDS roscpp rospy sensor_msgs message_runtime
)
add_executable(battery_subscriber src/battery_subscriber.cpp)
target_link_libraries(battery_subscriber ${catkin_LIBRARIES})
add_dependencies(battery_subscriber ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>

Scenario 3: Dependency on External ROS Package

Section titled “Scenario 3: Dependency on External ROS Package”

The Livox-ros-driver2 driver package must be installed and configured first. Refer to Livox Driver Installation Tutorial.

Problem: rostopic echo /livox/lidar only outputs point cloud array data, without standard message headers and LiDAR frame metadata.

Solution: The Livox-ros-driver2 driver package must be installed on the local terminal to correctly parse the custom message type of the /livox/lidar topic.