Welcome to MicroROS V2 Robot Car repository
3. Multimodal Visual Understanding + Basic Control
3. Multimodal Visual Understanding + Basic Control
1. Course Content
- Learn the large model's use of the robot's basic control functions.
- Analyze newly appearing key source code.
2. Preparation
2.1 Content Description
The virtual machine used by default with this product starts the Dify docker environment automatically at boot, so no additional startup is needed.
⚠️ The same test instructions will not produce exactly the same reply content from the large model, and will differ slightly from the screenshots in the tutorial. If you need to enhance or reduce the diversity of the large model's replies, refer to 【AI Large Model Development】-【RAG Knowledge Base Deployment】 to modify the knowledge base and sample library.
Virtual machine terminal, start the Dify environment:
sh ~/bringup_dify.sh

3. Running the Case
3.1 Starting the Program
Open the virtual machine terminal and enter the command to start the underlying proxy + camera topic:
xxxxxxxxxxros2 launch microros_v2_bringup car_base.launch.py

Open another virtual machine terminal and enter the command:
xxxxxxxxxxros2 launch multi_brains llm_agent_control.launch.pyAfter initialization is complete, the following content will be displayed:

Then open another terminal and start the text dialogue:
xxxxxxxxxxros2 run multi_brains terminal_client
3.2 Test Cases
Note: Servo 1 is the x-direction servo with a range of (-90-90), servo 2 is the y-direction with a range of (-90-0), and the initial position is (0, -45).
Reference test cases are given here. Users can create their own dialogue commands.
- The car moves forward 1 meter, backward 0.5 meters, then turns left 90 degrees, then turns right 90 degrees.
- Servo 1 rotates to 30 degrees, servo 2 rotates to -30 degrees, then returns to the initial position.
- Take photos around.
3.2.1 Case 1: "The car moves forward 1 meter, backward 0.5 meters, then turns left 90 degrees, then turns right 90 degrees"
Enter "The car moves forward 1 meter, backward 0.5 meters, then turns left 90 degrees, then turns right 90 degrees" in the text dialogue terminal. The terminal prints information as follows:

The robot decomposes this into four tasks to complete. After completing the tasks, it enters a waiting state.
3.2.2 Case 2: "Servo 1 rotates to 30 degrees, servo 2 rotates to -30 degrees, then returns to the initial position"
Enter "Servo 1 rotates to 30 degrees, servo 2 rotates to -30 degrees, then returns to the initial position" in the terminal. The terminal prints information as follows:

The robot decomposes this into three tasks to complete. After completing the tasks, it enters a waiting state.
3.2.3 Case 3: "Take photos around"
Enter "Take photos around" in the terminal. The terminal prints information as follows:

You can see that the robot takes photos in three directions and saves them, then analyzes the photos taken. After completing the task, it enters a waiting state. Photo paths:
xxxxxxxxxx~/microros_ws/cache/llm_observe_0.jpg llm_observe_1.jpg llm_observe_2.jpg

At this time, the instruction is directly passed to the execution-layer large model, and all conversation history is always retained. If the conversation becomes too long, we can input the "/reset" command again to let the robot end the current task cycle and start a new task cycle.

4. Source Code Analysis
This case uses the structure where the Dify execution layer outputs action functions, which are then distributed by llm_agent_node.py to different controllers for execution. Basic control, pan-tilt control, and visual photo taking are all completed in the same feedback loop, and there is no need to additionally start the old-version action service.
Current relevant source code paths:
xxxxxxxxxx~/microros_ws/src/multi_brains/multi_brains/llm_agent_node.py~/microros_ws/src/multi_brains/multi_brains/controllers/motion_controller.py~/microros_ws/src/multi_brains/multi_brains/controllers/ptz_controller.py~/microros_ws/src/multi_brains/multi_brains/services/dify_coordinator.py~/microros_ws/src/multi_brains/multi_brains/core/action_registry.pyCore actions:
xxxxxxxxxxmove_forward(speed, duration) Move forward, speed is the linear velocity, duration is the motion timemove_backward(speed, duration) Move backward, speed is the linear velocity, duration is the motion timeturn_left(angle, speed) Turn left in place, angle is the angle, speed is the angular velocityturn_right(angle, speed) Turn right in place, angle is the angle, speed is the angular velocityservo1_move(angle) Control servo 1 (horizontal)servo2_move(angle) Control servo 2 (tilt)servo_init() Pan-tilt returns to the initial positionobserve_surroundings() Pan-tilt turns to multiple directions to take photos and feeds the images back to Difyseewhat() Get the current frame and feed the image back to Difystop() Stop the chassis and the current continuous actionCore flow:
xxxxxxxxxxUser inputs a compound instruction -> Dify decision/execution layer outputs action JSON -> DifyCoordinator parses the response and actions -> llm_agent_node.py distributes actions according to action_registry -> MotionController publishes /cmd_vel to control the chassis -> PtzController publishes /cmd_ptz_angle to control the pan-tilt -> seewhat()/observe_surroundings() save images and upload them to Dify -> Dify continues to the next step or ends the task based on the action feedbackMotionController validates parameters such as speed, duration, and turning angle to prevent abnormal values output by the large model from directly entering chassis control. PtzController restricts the servo angle range; by default, servo 1 ranges from -90 to 90 degrees, and servo 2 ranges from -90 to 20 degrees. When the user inputs a new instruction, llm_agent_node.py interrupts the current action to ensure the robot executes the latest user intent.