Welcome to ROSMASTER M3 repository
15.Gesture Motion Control
Gesture Control Car Basic Movement
1. Program Function Description
After the function is enabled, the camera captures images and recognizes gestures to control the car's movement.
| Gesture | Action |
|---|---|
| Gesture "5" | Car forward |
| Gesture "1" | Car turn right |
| Gesture "2" | Car stop |
| Gesture "3" | Car backward |
| Gesture "4" | Car turn left |
MediaPipe Hands infers 3D coordinates of 21 hand joint landmarks from a frame

2. Program Startup**
2.1. Startup Commands
For Raspberry Pi 5 users, if the ROS container is not started, you need to start the container first,
xxxxxxxxxxbringup_m3Open a terminal inside the container,
xxxxxxxxxxexec_m3
- For Orin, RDK mainboard, start directly on the car end:
xxxxxxxxxxros2 launch m3_bringup mediapipe_demo.launch.py demo:=HandCtrlEnable this function, then place your hand in front of the camera. The screen will draw the finger shapes. After the program recognizes the gesture, it will send the speed to the chassis, thereby controlling the car's movement.

3. Core Code
Program code path:
xxxxxxxxxx~/yahboomM3_ws/code_ws/src/m3_common_demo/m3_common_demo/mediapipe/14_HandCtrl.py3.1. HandCtrl.py
Import key libraries
xxxxxxxxxxfrom yahboomcar_mediapipe.media_library import * #This library contains functions for hand detection and gesture recognitionGet finger data
xxxxxxxxxxframe, lmList, _ = self.hand_detector.findHands(frame)fingers = self.hand_detector.fingersUp(lmList)sum(fingers)fingers[]As you can see, first the hand is detected to get the lmList value, then it's passed to the fingersUp function. The fingersUp function is used to detect which fingers are extended, with extended fingers having a value of 1. You can see the specific code in media_library.py function, which has detailed explanations. It essentially determines if fingers are extended by judging the xy values of finger joints. The sum(fingers) function calculates the number of extended fingers, and fingers[] can be used to enumerate fingers. For example, the index finger is represented by fingers[1].
Publish speed to chassis
xxxxxxxxxxself.media_ros.pub_vel(x,y,z) #This function is also in media_library.py