Menu

StepperMotors

Perrotti

Stepper motor classes

Class StepperDouble is the publish class of hierarchy implemented in pStpCouple.h library. Implements several advanced features and allows to perform movements with high precision. There are 11 programmed movements that can be quantified in centimeters or degrees (depending on movement). Movements can also be stored in a buffer and then executed in sequence. It also offers the option of using arduino timer2 for pulse timing. Below some concepts used by library.

Operation mode
  void halfStepOn();
  void halfStepOff();
  void turboOn();
  void turboOff();

This library suports 3 diferent modes to operate the stepper motors:

  • Full step with 1 coil: (halfStepOff(), turboOff()) This is the default mode. For each pulse the motor performs one step and only one coil is used at time. It is the mode that consumes less energy, but also the one that has less torque.
  • Full step with 2 coils: (halfStepOff(), turboOn()) For each pulse the motor performs one step, but two coils are used. Torque and power consumption is twice of the mode with one coil.
  • Half step: (halfStepOn(), turboOff()) For each pulse the motor performs a half step alternating the previous two modes. The movement becomes smoother and more precise, as the number of steps per revolution of motor doubles. The power consumption and torque are in intermediate values to other modes.

Note: Is not a good ideia switch between half and full step modes after setup. This impairs the movement control of classes. However, you can swicth beetwen turboOn and turboOff modes whenever necessary.

Automatic acceleration

Stepper motors can reach reasonable speeds with relatively high loads (weight), but they can not reach their maximum speed at start if they have to carry a robot. They need to be accelerated gradually to gain inertia.
The class implement automatic acceleration and deceleration, that can be configured by the startSpeed and cruiseSpeed parameters of begin() method. Moves always start at startSpeed and automatically accelerate until they reach cruiseSpeed. At the end of movement the motors are decelerated until reaching startSpeed before stop. The values of these speeds depend on the motor used, but also on the weight of robot. It needs to be reviewed when the robot gains or loses significant weight.

Speeds should be informed in pulses per second.

Brake cut percent
#define STP_BRAKE_CUT_PERCENT     65

void setBrakeCutPercent(byte brakeCutPercent);

Turn movements require one of the wheels to be in brake state, ie with the coils on but not moving. Brake movement put both motors in brake state. This is a necessary situation to obtain accurate movement and emergency stops, but potentially dangerous. Causes current consumption to increase greatly and heats the motor and the driver board. If maintained for a long time, it may burn one of them. To protect the hardware and reduce energy consumption, whenever enters that state, the motor is turned off for some time at the end of each step. For example, if the pulse has a duration of 1000 microseconds and the cutoff percentage is 75%, the coils will be switched on for 750 microseconds and turned off the remaining 250. The STP_BRAKE_CUT_PERCENT define (pStpMotor.h) gives a default value, but the cutoff percentage can be setted by setBrakeCutPercent() method.

Movements

Here are listed the movements implemented by the classes:

#define mv_Off       0
#define mv_Ahead     1
#define mv_Back      2
#define mv_Brake     3
#define mv_SpinLf    4
#define mv_SpinRg    5
#define mv_TurnLf    6
#define mv_TurnRg    7
#define mv_TurnBkLf  8
#define mv_TurnBkRg  9
#define mv_CurveLf   10
#define mv_CurveRg   11
  • mv_Ahead: Move foward
  • mv_Back: Move back
  • mv_Brake: Put both motors in brake state (see topic above). Useful for emergency stops, but can not be kept for a long time under the risk of burning the drive boards or motors.
  • mv_SpinLf: Spin to left. Right wheel move foward and left wheel move back.
  • mv_SpinRg: Spin to right. Left wheel move foward and right wheel move back.
  • mv_TurnLf: The right wheel move foward and describe a circle around left wheel. Left wheel stay in brake state.
  • mv_TurnRg: The left wheel move foward and describe a circle around right wheel. Right wheel stay in brake state.
  • mv_TurnBkLf: The right wheel describe a circle around left wheel moving back. Left wheel stay in brake state.
  • mv_TurnBkRg: The left wheel describe a circle around right wheel moving back. Right wheel stay in brake state.
  • mv_CurveLf: Both wheels move forward, but the left wheel executes half of the steps of right wheel. The result is a curve to left.
  • mv_CurveRg: Both wheels move forward, but the right wheel executes half of the steps of left wheel. The result is a curve to right.
Move Params

The movements can be expressed in centimeters, degrees or pulses. For the mv_Ahead and mv_Back movements the moveParam parameter means centimeters. For spin, turn, and curve movements, moveParam is expressed in degrees. Finally, for the mv_Brake move, moveParam indicates the number of pulses.

Timer2 to timming pulses
#define STP_USE_TIMER2

The pulses for motors can be timed by arduino timer2 or by software. Using the timer2 makes timing more accurate and independent of the main loop processing. Thus, an eventual overprocessing in the main loop does not interfere with the robot movement. If you prefer not to use the timer2, just comment define STP_USE_TIMER2 and the timing will be done by software.

StepperCouple page


Related

Wiki: StepperCouple
Wiki: StepperDuo
Wiki: StepperSingle
Wiki: StpDuoBuff
Wiki: StpDuoTimer2

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.