Welcome to ROSMASTER R2 repository
10.3 Robot information release
3. Robot information release
According to different models, just set the purchased model in [.bashrc], X1 (normal four-wheel drive) X3 (Mailun) X3plus (Mailun robotic arm) R2 (Ackerman differential) etc. , this section takes X3 as an example
x#Raspberry Pi 5 master needs to enter docker first, please perform this step#If running the script into docker fails, please refer to ROS/07, Docker tutorial~/run_docker.sh#Multiple ros commands require multiple terminals to be executed in the same docker container. Please refer to the tutorials in Sections 07/5 and 5.8.Open the [.bashrc] file
xxxxxxxxxxsudo vim .bashrc
Find the [ROBOT_TYPE] parameter and modify the corresponding model
xxxxxxxxxxexport ROBOT_TYPE=X3 # ROBOT_TYPE: X1 X3 X3plus R2 X7This section takes X3, Mecanum wheel vehicle as an example.
3.1. Node subscription and publishing topics
3.1.1. Function package path:
xxxxxxxxxx~/yahboomcar_ws/src/yahboomcar_bringup
Functions that ROSMASTER needs to implement: speed control, speed information feedback, battery voltage feedback, buzzer control, and running water light control. (Note: In the version with a robotic arm, robotic arm control, robotic arm status feedback and PTZ control also need to be implemented)
3.2. View node data
3.2.1. Start
xxxxxxxxxxroslaunch yahboomcar_bringup yahboomcar.launch
3.2.2, View topic list
xxxxxxxxxxrostopic list

xxxxxxxxxxrosrun rqt_topic rqt_topic #View topics graphically
3.2.3. Program flow chart

3.2.4, core code (Mcunamu_driver.py)
xxxxxxxxxxGet data (core board -> host computer) edition.data = self.car.get_version() battery.data = self.car.get_battery_voltage() ax, ay, az = self.car.get_accelerometer_data() gx, gy, gz = self.car.get_gyroscope_data() mx, my, mz = self.car.get_magnetometer_data() vx, vy, angular = self.car.get_motion_data()Publish data (host computer -> host computer) self.EdiPublisher.publish(edition) self.volPublisher.publish(battery) self.imuPublisher.publish(imu) Note: The imu data here is a combination of gyroscope and acceleration data. self.magPublisher.publish(mag) self.velPublisher.publish(twist)Processing of acquired data (topic receiving data, transmission of data between nodes) cmd_vel_callback(self, msg) RGBLightcallback(self, msg) Buzzercallback(self, msg)Release data (host computer -> core board) self.car.set_car_motion(vx, vy, angular) self.car.set_colorful_effect(msg.data, 6, parm=1) self.car.set_beep(1) or self.car.set_beep(1)3.2.5. Analysis of three callback functions
xxxxxxxxxx # Running water light control, server callback function RGBLight control ''' effect=[0, 6], 0: Stop light effect, 1: Running water light, 2: Marquee light, 3: Breathing light, 4: Gradient light, 5: Starlight, 6: Battery display speed=[1, 10], the smaller the value, the faster the speed changes. ''' # Car motion control, subscriber callback function ''' vx = msg.linear.x vy = msg.linear.y angular = msg.angular.z Note: Because this model is a Mecanum wheel, it can move on the y-axis. It is not applicable to other models. ''' #Buzzer control, subscriber callback function ''' self.car.set_beep(1): Turn on the buzzer self.car.set_beep(0): Turn off the buzzer '''3.2.6. Use the rostopic pub command to send running light control, speed control, and buzzer control commands.
xxxxxxxxxxRunning water light controlrostopic pub /RGBLight std_msgs/Int32 1 #Turn on the running water lightspeed controlrostopic pub /cmd_vel geometry_msgs/Twist "linear: x: 0.0 y: 0.0 z: 0.0angular: x: 0.0 y: 0.0 z: 0.1" #The car moves at an angular speed of 0.1Buzzer controlrostopic pub /Buzzer std_msgs/Bool true #Turn on the buzzer, send false if turned off3.2.7. Use the rostopic echo command to view speed information and battery voltage