日本語 | English |
GyroM5
- GyroM5 is an OSS for turning your M5AtomMatrix / M5StickC into steering assit gyro of RC drift car.
- Sketch GyroM5Atom.ino installed M5AtomMatrix can stabilize drift driving of your RC car.
- Sketch GyroM5Stick.ino installed M5StickC can stabilize drift driving of your RC car.
DEMO
This Tamiya RC car (SU-01) with GyroM5 is performing “RWD drifting”.
https://user-images.githubusercontent.com/64751855/117535983-a1d76280-b033-11eb-9f59-ec6aaef0b9b0.mp4
Features
GyroM5 has unique features.
- Feedback control
Auto steering to follow target yaw rate by PID control - Parameter setting
Setting PID control parameters by smartphone - Remote gain tuning
Tuning a PID control parameter by CH3 signal - End point setting
Setting steering end point by CH1 signal - IMU calibration
Auto calibration of zero points in CH1 and IMU - Monitoring display
Displaying RC/IMU signals and PID parameters in LCD - Drift detection
Detecting counter-steer and appearing by LCD
Requirement
These hardwares are required for GyroM5.
- Hobby RC car
RC car equipped with standard and separated receiver/servo units. - Standard PC
PC installed with Arduino IDE and equipped with USB. - M5StickC
“M5StickC” not “M5StickC Plus” is required. - Parts for wire harness
One servo extention cable, and one pin headder (8-pin male). - Soldering tool
For assembling wire harness.
Usage
The outline of usage is as follows. The details are in next section.
Hardware setting
- Install Arduino IDE on your PC.
- Setup Arduino IDE for ESP/M5StickC.
- Connect your PC and M5StickC with USB.
- Install sketch GyroM5Stick.ino on your M5StickC.
- Install GyroM5/M5StickC on your RC car with LCD up.
Software setting
- Turn on your RC car.
- Wait for GyroM5 HOME state.
- Setup steering end point.
- Setup initial PID control gains (KG=50, KP=50, KI=30, KD=10).
- Run RC car and adjust PID control gains.
Daily usage
- Turn on your RC car.
- Wait for GyroM5 HOME state.
- Run RC car and adjust PID control gains.
Note
The details are as follows.
Wiring
Wire GyroM5/M5StickC to RC receiver/servo units, as explained in the table below.
M5StickC | in/out | RC units |
---|---|---|
G26 | in | Reciever CH1 |
G36 | in | Reciever CH3 |
G0 | out | Servo CH1 |
GND | in | Reciever minus |
5Vin | in | Reciever plus |
An example image of assembled wire harness is as follows.
Caution: Signal levels in M5StickC (3.3v) and RC units (5.0v or more) are generally different. My RC units use 5.0-6.0v and work no trouble with directly connected M5StickC. But higher volotage (over 6.0v) RC units may damage your M5StickC.
Turning On/off
M5Stick is known to have bugs in its power managment. Find hints for trouble-shooting with google search like keyword “m5stickc not turning on”.
Monitoring LCD
GyroM5 has five states below. One state transits to anothr state at button [A]/[B] or timeout event.
- State “HOME” is the home, transits to “WIFI” by [A] and transits to “ENDS” by [B].
- State other than “HOME” accepts A/B button or returns to “HOME” by timeout.
- Remote gain tuning by CH3 is initially disabled.
state | transition | descripition |
---|---|---|
WAIT | RC signal | waits for PWM signal from RC receiver |
INIT | Timeout | calibrates zero points in CH1 and gyrosensor, dont move RC car |
HOME | [A],[B] | displays RC signals, IMU inputs and PID gains |
WIFI | [A] | WiFi access point and accepts setting commands |
ENDS | [B] | setup CH1 steering end points |
GyroM5’s web server returns the following page for various setting. In this page, you can setup PID parameters, PWM frequency and so on.
Tuning
GyroM5’s control algorithm is explained for tuning parameters.
Algorithm
GyroM5 uses generic feedback control algorithm “PID control”.
In the above PID control, the plant/process is your RC car. The target r, the output y and the control u are as follows.
- target: r = ch1_in = CH1 input from RC receiver
- output: y = Kg*wz = Yaw rate of RC car
- control: u = ch1_out = CH1 output to RC servo
GyroM5 attempts to minimize error value e by adjusting control variable u.
- error: e = r - y = ch1_in - Kg*wz
- control: u = PID(e) = Kp * e + Ki * INT(e) + Kd * DOT(e)
INT is time integral operator, DOT is time derivative operator.
Parameters
You can confirm/adjust the integer PID gains by LCD, A/B buttons and CH1. The integer gains (in uppercase) are normalized from -100 to 100, and are related to the real gains (in lowercase) as follows.
- Yaw rate “wz” is in (radian per sec):
IMU sensored values in physical units. - Input/output “ch1” is in 16bits (0〜64k):
Pulse width (0〜20ms=1000ms/50Hz) in 16bit (0〜2^16-1) integer. - Observation Gain: Kg = KG/20.0
Larger Kg becomes, smaller yaw rate per steering becomes. - Proportional Gain: Kp = KP/50.0
Larger Kp becomes, more fastly error decreases but may vibrate. - Integral Gain: Ki = KI/250.0
Larger Ki becomes, more slowly error decreases, and smaller final error is. - Derivative Gain: Kd = KD/5000.0
Larger Kd becomes, more quickly error decreases but may vibrate.
Initial parameters are recommended to set the integer gains “KG=50, KP=60, KI=30, KD=10”. Special integer gains “KG=KI=KD=0 and KP=50” are as same as the setting “pass throw: u=r”. The plus/minus sign of KG is used for normal/reverse operation in steering servo.
Testing
My RC car for testing GyroM5 is as follows.
item | model |
---|---|
chassis | Tamiya SU-01 |
body | Tamiya Jimmny Willy (SJ30) |
tire | TOPLINE drift tire |
RC TX | Tamiya fine spec 2.4GHz |
RC RX | Tamiya TRE-01 |
RC ESC | Tamiya TRE-01 |
RC servo | Yokomo S-007 |
battery | 7.4V LiPo 1100mAh |
motor | 370 type |
Hints for “RWD drifting” are listed bellow.
- Larger steering angle is better for controlability.
- Faster steering servo is also better.
- Slippy tires are easier to drift by low power motor/battery.
Roadmap
The followings are some ideads for improving your GyroM5.
- Wireless setting GyroM5 by smartphone
- Automatic tuning of PID gain parameters
- Assiting not only steering but also throttle
- Reading PWM input without blocking
- Automatic detection of installed direction
- Recording and analysis of driving data
Author
The author bought a small RC car kit (Tamiya SU-01) for indoor playing under COVID-19. After purchasing, I watched the RC car YouTube channel and became interested in “RC drift car” that did not exist in my childhood. The “RC drift car” is already established as a genre of RC car, and the shortest course to play “RC drift car” is to get dedicated products like Yokomo YD-2.
But in my case, I noticed the “RC drift car” after purchasing the kit, and I believed that any RC car can perform “stable drift driving” by high speed control. So I tried to make steering assit gyro to stabilize RWD drift driving for my small car.
I enjoyed making this GyroM5, and I thought this may be a good material to learn programming and control algorithm while playing RC car. So I release the source code of GyroM5 for expecting that someone use this material for STEM education, or persuading your parents to buy hobby RC car.
I am happy if somebody could reproduce GyroM5 or customize it by themselves.
(^_^)
Reference
Radio Control Car
Automobile Drifting
- Automotive Vehicle Dynamics
- Vehicle Running Stability Analysis and Spin Control
- On the dynamics of automobile drifting
- Analysis and control of high sideslip manoeuvres
- Stabilization of steady-state drifting for a RWD vehicle
Software
- M5StickC Library
- M5StickC non official reference
- M5Stack official documents
- Arduino IDE
- PID Controller - Wikipedia