Closed Loop Position Control in Stepper Motors
Super precise control by just adding one component to your setup
Introduction
Actuators are an integral part of robotics, they’re the components that provide motion to the joints in robotics. A general classification of actuators could be rotary and linear. The most common rotary actuators used in mechatronic systems are electric motors.
Driving these actuators isn’t a problem as it’s pretty straightforward even with complicated motors, where ready-made drivers should do the job.
Controlling the motors is a different problem. Controlling an actuator is crucial as it directly or indirectly controls the position or velocity of a joint in a robot.
Controlling the position or velocity helps us keep track of and plan the trajectory of said robot.
For the control loop to work, we would need to first get the position or velocity feedback from the joint, or the actuator controlling the joint.
Robotic Arms, for example, require the current position of the arm and a goal position to then plan a trajectory.
Low-cost robotic arms do not have a closed-loop system for control. These arms usually have hobby RC servo motors and they form the kinematic chain. These hobby servo motors usually do not have any form of feedback as they have their own control within the servo. In such cases, we just send a control signal to the motor and hope it’s reached the position. We also do not have any idea of the current position of the robot, we just know the last goal position we sent it to.
This poses a problem when we start the robot and have no idea where the start position is. This leads to awkward jumps for the first trajectory.
The Solution
Enter AMS AS5600. The absolute encoder can solve this very issue.
The AS5600 is a 12-bit absolute encoder that works with a diametrically polarized magnet and sends position data over the I2C protocol.
When the magnet is positioned above the sensor, we can figure out with a 12-bit precision what orientation the magnet is at any given point in time.
Testing
For the test setup, we’ve taken a NEMA17 stepper motor coupled with a TB6560 micro-stepping driver. They are controlled by an Arduino Mega 2560 microcontroller board.
The AS5600 is mounted to the back of the motor with a custom 3d printed bracket, with the magnet mounted to the shaft, placing it above the sensor, giving the sensor the shaft position (which we need)
We first import the AS5600 library . First, we use the readAngle example to confirm that the angle feedback is being read properly.
We write a small script that takes the angle specified via the Arduino serial monitor and sets that as the goal position for the stepper motor.
Thanks for reading!