Established: 2024/04/29 Updated: 2024/04/29
The ROS2 topic message collection for the robot vehicle ver. 1 project.
- ROS2
Foxyor later (Humblerecommended) Install ROS2 from official website: ROS2 official website or simply run the following command to automatically install ROS2:NOTE: The script only supportscurl -fsSL ftp://61.220.23.239/scripts/install-ros2.sh | bashFoxyandHumbleversions depending on the Ubuntu version. NOTE: The script will create a new workspace at~/ros2_ws. NOTE: The script will create an aliashumbleorfoxyfor global ROS2 environment setup (e.g.source /opt/ros/<$ROS_DISTRO>/setup.bash) depending on the ROS2 version. - vehicle_interfaces
- libopencv-dev
- python3-opencv
- nlohmann-json3-dev
The required packages are listed in the requirements_apt.txt file. Install the required packages by running the following command:
xargs sudo apt install -y < requirements_apt.txtNOTE: The required packages will be installed automatically while installing the package using the (vcu-installer)[https://github.com/cocobird231/RV1-vcu-install.git].
There are two ways to install the package: manually or using the vcu-installer.
- Check if
vehicle_interfacespackage is installed. If not, install the package by following the instructions in the vehicle_interfaces. - Clone the repository under
~/ros2_ws/srcand rename it tocpp_dataserver3:git clone https://github.com/cocobird231/RV1-dataserver.git cpp_dataserver3
- Change the directory to the
~/ros2_wsworkspace and build the package:NOTE: The package is installed in the local workspace.# Change directory to workspace. cd ~/ros2_ws # Source the local environment. . install/setup.bash # Build the package. colcon build --symlink-install --packages-select cpp_dataserver3
-
Run the installer and press
Scanbutton under Package Management window. If the installer not installed, install the installer by following the instructions in thevcu-installer. -
Checked the
Data Server 3checkbox under package list, right-click to modify the internet setting, then press theInstallbutton to install the package. -
The installer will create the start-up script for the package under
/etc/xdg/autostartdirectory. The package will be started automatically after the system boot-up.
The package contains two executables: sub and control. The sub executable is used to run the main service, while the control executable is used to control the service.
-
Source the local workspace:
source ~/ros2_ws/install/setup.bash
-
Run the main service:
-
Using the
launch:ros2 launch cpp_dataserver3 launch.py
NOTE: The launch file parsed the
common.yamlfile to set the parameters. Thecommon.yamlfile is located in thecpp_dataserver3/launchdirectory. NOTE: Thecommon.yamlfile default the namespace toV0. -
Using the
run:ros2 run cpp_dataserver3 sub
-
-
Source the local workspace:
source ~/ros2_ws/install/setup.bash
-
Run the control service:
ros2 run cpp_dataserver3 control
NOTE: If the main service is using the namespace (e.g.
V0), the control service should use the same namespace to control the main service:ros2 run cpp_dataserver3 control --ros-args -r __ns:=/V0
The control executable demonstrates the control of the data server using DataServer.srv under vehicle_interfaces package. The DataServer.srv contains the following items:
# Request field
DataServerStatus request # Send DataServerStatus to data server.
# Response field
bool response # Whether the service is successfully executed.
string reason # # If response flase, describes the reason.
DataServerStatus status # Response current data server status.The DataServerStatus message can be used to describe the control signal of data server, or used to describe the current status of data server. The DataServerStatus message contains the following items:
# The action of the data server. E.g. set timer, period or do nothing. See DataServerStatus.msg for more details.
uint8 server_action
# The status of scanning timer. Set to TIMER_STATUS_XXX.
uint8 server_scan_timer_status
# The period of scanning in _ms. Server will ignore this if value <= 0.
float64 server_scan_period_ms
# The status of sampling timer. Set to TIMER_STATUS_XXX.
uint8 server_sample_timer_status
# The period of sampling in _ms. Server will ignore this if value <= 0.
float64 server_sample_period_ms
# The status of dumping timer. Set to TIMER_STATUS_XXX.
uint8 server_dump_timer_status
# The period of dumping in _ms. Server will ignore this if value <= 0.
float64 server_dump_period_ms
# The status of countdown timer. Set to TIMER_STATUS_XXX.
uint8 server_countdown_timer_status
# The period of countdown in _ms. Server will ignore this if value <= 0.
float64 server_countdown_period_msThe common.yaml file is used to set the parameters for the main service. The parameters are listed below:
topic_monitor:msg_filter: (vector) The message type filter list.scan_period_ms: (double) Scan the topic list in every period (ms). Timer call function to scan the whole topic list, and create new subscription nodes for the new topic.
msg_record:sample_period_ms: (double) The period of sample timer (ms). Timer call function to grab the latest message from each subscription node and store it in the buffer.dump_period_s: (double) The period of dump timer (s). Timer call function to dump the message buffer to the JSON file.countdown_duration_s: (double) The duration of countdown timer (s). Timer call function to stop recording the message and dump the rest of the message buffer to the JSON file.img_threads: (int) Number of threads for image SaveQueue. The SaveQueue will create the threads for image saving process.gnd_threads(not used): (int) Number of threads for ground truth SaveQueue. The SaveQueue will create the threads for ground truth saving process.dump_path: (string) The path to store the record file. The JSON file will be stored under<dump_path>/json, and the specificSaveQueueSubNodewill store data under<dump_path>/<sub_node_name>. E.g. The subscription node_V0_zed_rgb_0_subnodewill store the image data under<dump_path>/_V0_zed_rgb_0_subnode/.enable_control: (bool) Enable the control service. If true, the service will be idle until the control service sends the command to start the recording. Otherwise, the service will start recording immediately after the service is started.
service_prop:serviceName: (string) The service name. The service name revealed on the ROS2 network.
generic_prop:namespace: (string) The namespace of the node. The namespace is used to separate the services.nodeName: (string) The node name. The node name revealed on the ROS2 network.id: (int) The node id. The id of the node.
vehicle_interfaces/msg/Chassis: chassis motor information could be published byControlServeror other controller node.vehicle_interfaces/msg/Distance: range sensor information published byUltraSoundPublisherunderpy_ultrasoundpackage.vehicle_interfaces/msg/Environment: environment information published bySensePublisherunderpy_sensepackage.vehicle_interfaces/msg/GPS: GPS information published byGPSPublisherunderpy_gpspackage.vehicle_interfaces/msg/IDTable: not used.vehicle_interfaces/msg/Image: image information could be published byRGBImagePublisherundercpp_webcampackage orZEDPublisherundercpp_zedcampackage.vehicle_interfaces/msg/IMU: IMU information published bySensePublisherunderpy_sensepackage.vehicle_interfaces/msg/MillitBrakeMotor: not used.vehicle_interfaces/msg/MillitPowerMotor: not used.vehicle_interfaces/msg/MotorAxle: axle motor information published byChassisMotorPublisherunderpy_chassispackage.vehicle_interfaces/msg/MotorSteering: steering motor information byChassisSteeringPublisherunderpy_chassispackage.vehicle_interfaces/msg/QosUpdate: QoS update information published byQoSServer.vehicle_interfaces/msg/SteeringWheel: steering wheel information could be published byControlServeror other controller node.vehicle_interfaces/msg/UPS: not used.vehicle_interfaces/msg/WheelState: not used.
The data server aims to record the ROS2 topic message into JSON file. For those large scale data structure like image, point cloud, etc., the data server supports the custom save queue method, allow the user to seperate the data into JSON record file and the specific folder. For instance, the image data will be stored in the specific folder while JSON record file will store the image path and other information.
The custom message type could be easily added by modifying several steps:
-
Add the message type to the
msg_filterlist in thecommon.yamlfile. -
In
record_msg.h, specialize the make function for the custom message type, there are three scenarios could be considered:-
The subscribe ROS2 message type can be directly stored in the record buffer. E.g. simple data structure like imu, gps, distance, etc.. In this case, user does not need to modify the make function, the data server will automatically store the message in the record buffer.
-
The subscribe ROS2 message type need to be converted to the custom record structure then stored in the buffer. E.g. modify the subscribed message then store the modified message in the buffer. In this case, user need to specialized the
make_record_msg_2function. The tparammsgTis the subscribed ROS2 message type, the tparamrmsgTis the custom record structure to be recored into JSON file. The function return the shared pointer of theRecordMsg<rmsgT>. -
The subscribe ROS2 message data need to be stored in the specific folder using
SaveQueue. E.g. the image message, we convert the image message to the image record structure, then push the image data to theSaveQueuefor saving the image data in the specific folder. In this case, user need to specialized themake_record_msg_3function. The tparammsgTis the subscribed ROS2 message type, the tparamrmsgTis the custom record structure to be recored into JSON file, the tparamsmsgTis the custom save queue structure. The function return the shared pointer of theRecordMsg<rmsgT>.
-
-
For the
scenario 3, user need to specialized the_saveCbFuncfunction insave_queue.hfile to implement the saving method. The_saveCbFuncfunction arguments takes the inputPairQue<smsgT>. ThePairQuecontains the file name and data pairs. The file name should be the data saving path. -
In
dump_json.h, user need to specialized theRecordMsgToJSONfunction to dump the custom record structure into JSON file. TheRecordMsgToJSONfunction arguments takes the reference of the JSON objectjson, and a shared pointer ofRecordMsg<rmsgT>. Append the custom record structure tojson. -
In
scannode.h, append the new custom message name underline 235forScanNodeto support the message. Atline 278, forscenario 1, addSubNode<msgT>shared pointer tothis->subNodes_; forscenario 2, addSubNode2<msgT, rmsgT>shared pointer tothis->subNodes_; forscenario 3, addSaveQueueSubNode<msgT, rmsgT, smsgT>shared pointer tothis->subNodes_.