Overview
For applications that require motion control of a connected motor ClearCore provides a motion generation class called StepGenerator. StepGenerator is one of the parent classes of MotorDriver.
This allows all motor configuration functions and motion generation functions to be accessed by the same MotorDriver object.
The StepGenerator class is designed to facilitate features of a Teknic ClearPath motor, however generic stepper motor drives may be used as well. For simplicity's sake this document will assume a
ClearPath motor is being used when describing the features of the StepGenerator class.
Wiring and Initialization
- Before beginning to use the ClearCore, set up and connect a ClearPath motor to a host PC. Then, using Teknic's MSP software, configure and tune the ClearPath to the desired specifications. For
more information on these steps refer to the manual for your ClearPath motor found here.
- Using MSP, set the ClearPath's mode to Step and Direction. The StepGenerator will not function correctly if the ClearPath is in another operational mode.
- Attach the ClearPath to a motor connector, M-0, M-1, M-2, or M-3, on the ClearCore using the blue 8-pin data cable (Teknic P/N CPM-CABLE-CTRL-MM660).
- Any of the four connectors may be used in any order. For example, M-2 may be used without occupying M-0 and M-1.
- Using the ClearCore's MotorManager, set the motor connector into Connector::CPM_MODE_STEP_AND_DIR mode using the MotorManager::MotorModeSet() function. The StepGenerator will not function if the
connector is in another mode.
- The MotorModeSet() function sets a pair of motor connectors into the specified mode. Choose the pair that includes the connector you'd like to use. The pairs are M-0/M-1 and M-2/M-3.
Motion Parameters
The StepGenerator generates a move profile using pre-defined motion parameters set by the user. These parameters may be changed "on the fly"; newly commanded moves will immediately interrupt any currently active move. An easy way to check the move's state, provided by StepGenerator, is by polling the StepGenerator::StepsComplete() function. This will return a boolean value representing whether the StepGenerator is outputting steps. Note that depending on your mechanics the motor shaft may still be moving even if the value is false.
Position Reference
- The StepGenerator's position reference may be read or set directly through code.
}
void PositionRefSet(int32_t posn)
Sets the absolute commanded position to the given value.
Definition StepGenerator.h:164
volatile const int32_t & PositionRefCommanded()
Accessor for the StepGenerator's position reference.
Definition StepGenerator.h:182
MotorDriver ConnectorM0
M-0 connector instance.
- The position reference resets to zero at the beginning of code execution. It WILL NOT save between board resets.
- The position reference is entirely internal to the ClearCore. The StepGenerator's position reference will not reflect a ClearPath's own shaft position as displayed in the MSP software.
Velocity and Acceleration
- Maximum velocity and acceleration values may be set to give the desired motion profile (in units of step pulses per second and step pulses per second2, respectively).
void AccelMax(uint32_t accelMax)
Sets the maximum acceleration in step pulses per second^2.
void VelMax(uint32_t velMax)
Sets the maximum velocity for position moves, in step pulses per second.
- Setting a velocity limit using StepGenerator::VelMax() will not limit the allowable velocities when commanding a velocity move using StepGenerator::MoveVelocity().
Motion Commands
The StepGenerator class provides movement functions which can have various behaviors depending on the pre-defined motion parameters and the parameters passed into the functions.
Regardless of which move command is issued, they may both be stopped by calling the StepGenerator::MoveStopAbrupt() function.
Positional Move
- Generates a triangle movement profile that obeys the set maximum velocity and acceleration limits.
- The function returns true if the movement can start. The move will be rejected if the commanded position reference would result
in no motion or if an alert is present in the motor's Alert Register.
- The StepGenerator::Move() function by default commands a relative move.
virtual bool Move(int32_t dist, MoveTarget moveTarget=MOVE_TARGET_REL_END_POSN) override
Issues a positional move for the specified distance.
- Setting the moveTarget parameter to
MOVE_TARGET_ABSOLUTE
will command a move to the (passed-in) absolute position reference.
Velocity Move
- Begins a continuous move at the specified velocity using the pre-defined max acceleration.
- Calling StepGenerator::MoveVelocity() will overwrite any currently active positional move.
- The function returns true if the movement can start. The move will be rejected if the commanded position reference would result
in no motion or if an alert is present in the motor's Alert Register.
virtual bool MoveVelocity(int32_t velocity) override
Issues a velocity move at the specified velocity.
- Commanding a velocity move during another velocity move will cause the first move to smoothly accelerate/decelerate to the new velocity.