After the first four sections of preparation work, it can be said that everything has, only the east wind, this east wind is a high-power charging treasure, tried their own small capacity, can not take up, had to borrow a 10000maH, 5V/2A output, X3 perfect start, good excited.
One, preparation.
Details of the preparation are described in the preceding sections.
Rising Sun X3 PI has burned the Ubuntu20.0.4 or Linux system image provided by Horizon.
The Rising Sun X3 has successfully installed TogetherROS.
The F37 sensor has been installed on the Rising Sun X3 PI.
PCS on the same network segment (wired or connected to the same wireless network) as the X3pcs. The first three segments of IP addresses must be the same.
Car hardware preparation
Two, start the official routine.
Log in using MobaXterm, SSH, set up a terminal, and enter the following command
source /opt/tros/setup.bash
cp -r /opt/tros/lib/mono2d_body_detection/config/ .
ros2 launch body_tracking hobot_body_tracking_without_gesture.launch.py
Three, start the car to receive node control program.
The body recognition program on it is completely official, unchanged. But the car control program, which needs to be modified according to its own car, needs another program to receive messages. My car and the official is different, so can not directly use the official code, the principle of the official introduction:
My X3 send direct control GPIO port, to control the driver board, refer to a user in the forum to modify the program, the following is my subscription /cmd_vel topic control message program
from geometry_msgs.msg import Twist
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
import Hobot.GPIO as GPIO
import time
import sys
import os
import serial
import serial.tools.list_ports
output_pin26 = 26
output_pin28 = 28
output_pin38 = 38 # BOARD 缂栫爜 38
output_pin40 = 40
GPIO.setmode(GPIO.BOARD)
GPIO.setup(output_pin26, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(output_pin28, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(output_pin38, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(output_pin40, GPIO.OUT, initial=GPIO.LOW)
uart_dev='/dev/ttyS3'
baudrate = 115200
try:
ser = serial.Serial(uart_dev, int(baudrate), timeout=1) # 1s timeout
print("open serial sucess")
except Exception as e:
print("open serial failed!\n")
class CmdNode(Node):
def __init__(self,name):
super().__init__(name)
self.sub_cmd = self.create_subscription(Twist,"cmd_vel",self.recv_cmd_callback,6)
def recv_cmd_callback(self,cmd):
self.cmd_speed=cmd._linear._x
self.cmd_angular=cmd._angular._z
# print("get msg sucess")
if(self.cmd_speed>0):
GPIO.output(output_pin26, GPIO.HIGH)
GPIO.output(output_pin28, GPIO.LOW)
GPIO.output(output_pin38, GPIO.HIGH)
GPIO.output(output_pin40, GPIO.LOW)
print("111")
elif(self.cmd_angular>0):
GPIO.output(output_pin26, GPIO.LOW)
GPIO.output(output_pin28, GPIO.LOW)
GPIO.output(output_pin38, GPIO.HIGH)
GPIO.output(output_pin40, GPIO.LOW)
print("222")
elif(self.cmd_angular<0):
GPIO.output(output_pin26, GPIO.HIGH)
GPIO.output(output_pin28, GPIO.LOW)
GPIO.output(output_pin38, GPIO.LOW)
GPIO.output(output_pin40, GPIO.LOW)
print("333")
else:
GPIO.output(output_pin26, GPIO.LOW)
GPIO.output(output_pin28, GPIO.LOW)
GPIO.output(output_pin38, GPIO.LOW)
GPIO.output(output_pin40, GPIO.LOW)
print("444")
def main(args=None):
rclpy.init(args=args)
sub_node = CmdNode("sub")
rclpy.spin(sub_node)
rclpy.shutdown
if __name__ == '__main__':
main()
commands
source /opt/tros/setup.bash
python3 /app/40pin_samples/zyd_ros_cmd_control.py
