Main Content

With stepper motor via microstepping, digital motion processing, auto tuning via Twiddle Algorithmus, cascaded PID Controller

I bought my first Arduino three years ago. I was fascinated by by the idea of a self-balancing-robot and this was my first project.

I underestimated the difficulties, so the development took a long time. Many changes were necessary:

The most important changes were:

- Change from Arduino Mega to Arduino DUE
- Change from direct-current-motor with encoder to stepper motor
- Use of digital motion processing
- MP 6500 stepper motor driver carrier
Features of the Robot
- Control of the robot via an Android Bluethoot App.
- Stepper Motor, Unipolar/Bipolar, 200 Steps/Rev, 42×48mm, 4V, 1.2 A/Phase
- Stepper Motor Driver Carrier can deliver up to 1.5 A per phase continuously, four different step resolutions: full-step, half-step, 1/4-step, and 1/8-step.
- cascaded PID Controller for Motor and for Position
- Task Dispatcher via Interrupt
- PWM Controller
- MPU-6050 sensor with accelerometer and gyro, using Digital Motion Processing with MPU-6050
- Auto Tuning via Twiddle Algorithmus
- Battery Control
- Software Design Object oriented
- planned Step: drive in all diretcions
Running only at Arduino Due

Stepper Motors
I decided to use Stepper engines because they offer the following advantages:

Exact positioning, no accumulated errors
Holding torque in rest position
No deceleration/lag due to the moment of inertia of the motor
simple position sensing by counting PWM signal
MPU-6050 Accelerometer + Gyro
The MPU-6050 sensor contains a MEMS accelerometer and a MEMS gyro in a single chip. It is very accurate, as it contains 16-bits analog to digital conversion hardware for each channel. Therefor it captures the x, y, and z channel at the same time. The sensor uses the I2C -bus to interface with the Arduino.

I used Digital Motion Processing with the MPU-6050 sensor, to do fast calculations directly on the chip. This reduces the load for the Arduino.

Because of the orientation of my board, I used yaw/pitch/roll angles (in degrees) calculated from the quaternions coming from the FIFO. By reading Euler angle I got problems with Gimbal lock.

MP6500 Stepper Motor Driver Carrier
The used stepper motor driver lets you control one bipolar stepper motor at up to approximately 1.5 A per phase continuously without a heat sink or forced air flow ( Datasheet).

PID auto Tuning with Twiddle
Twiddle is an algorithm that tries to find a good choice of parameters for an algorithm. The Twiddle algorithm is used for auto tuning of PID parameter.

Cascaded PID Controler
The robot is controlled by cascaded PID controllers. Two controllers are responsible for driving the motors (right and left side). Two additional controllers for controlling the position of the robot.

The motor controller ensures that the robot remains upright. The Position Controler ensures that the robot maintains its correct setpoint prescribed position.

Cascade control is a cascading of several controllers; the associated control loops are nested in each other. The controller output variable of one controller (master controller, Position) serves as the reference variable for another (slave controller, Motor).

The PID controllers are implemented in the “PIDControl” class. 4 instances of the class are instantiated for the 4 controllers.

The standard PID algorithm was slightly modified after longer test series. To the P-component the parameter Kx multiplied by the I-component was added.

Before this change the robot always wanted to run away. A simple increase of the I-portion made the robot unstable. This solution certainly depends strongly on the structure of the robot (weight, centre of gravity, etc.).

PWM Controler
To generate the PWM signals I modified the library of “randomvibe . ( The PWM controller is implemented in the DuePWMmod class. Unique frequencies set via PWM Clock-A (“CLKA”) and Clock-B (“CLKB”).”

Link to article