Stepper
[Libraries]

The Stepper Motor subsystem provides speed and position control for one or two stepper motors. More...


Functions

int Stepper_SetActive (int index, int state)
 Sets whether the specified Stepper is active.
int Stepper_GetActive (int index)
 Check whether the stepper is active or not.
int Stepper_SetPosition (int index, int position)
 Set the position of the specified stepper motor.
int Stepper_SetPositionRequested (int index, int positionRequested)
 Set the destination position for a stepper motor.
int Stepper_SetSpeed (int index, int speed)
 Set the speed at which a stepper will move.
int Stepper_GetSpeed (int index)
 Get the speed at which a stepper will move.
int Stepper_GetPosition (int index)
 Read the current position of a stepper motor.
int Stepper_GetPositionRequested (int index)
 Read the destination position of a stepper motor.
int Stepper_Step (int index, int steps)
 Simply take a number of steps from wherever the motor is currently positioned.
int Stepper_SetDuty (int index, int duty)
 Set the duty - from 0 to 1023.
int Stepper_GetDuty (int index)
 Get the duty Read the value previously set for the duty.
int Stepper_SetBipolar (int index, int bipolar)
 Declare whether the stepper is bipolar or not.
int Stepper_GetBipolar (int index)
 Get the bipolar setting Read the value previously set for bipolar.
int Stepper_SetHalfStep (int index, int halfStep)
 Declare whether the stepper is in half stepping mode or not.
int Stepper_GetHalfStep (int index)
 Read whether the stepper is in half stepping mode or not.

Detailed Description

The Stepper Motor subsystem provides speed and position control for one or two stepper motors.

Up to 2 stepper motors can be controlled with the Make Application Board. Specify settings for your stepper motor by setting whether it's:

Positioning

You can generally use the stepper motor in 2 modes - absolute positioning or relative positioning.

For absolute positioning, call Stepper_SetPositionRequested() with the desired position, and the motor will move there. You can read back the stepper's position at any point along the way to determine where it is at a given moment. The board keeps an internal count of how many steps the motor has taken in order to keep track of where it is.

For relative positioning, use Stepper_Step( ) to simply move a number of steps from the current position.

See the Stepper Motor how-to for more detailed info on hooking up a stepper motor to the Make Controller.


Function Documentation

int Stepper_GetActive ( int  index  ) 

Check whether the stepper is active or not.

Parameters:
index An integer specifying which stepper (0-1).
Returns:
State - 1 (active) or 0 (inactive).
Example
  if( Stepper_GetActive(1) )
  {
    // Stepper 1 is active
  }
  else
  {
    // Stepper 1 is inactive
  }

Definition at line 176 of file stepper.c.

int Stepper_GetBipolar ( int  index  ) 

Get the bipolar setting Read the value previously set for bipolar.

Parameters:
index An integer specifying which stepper (0 or 1).
Returns:
1 for bipolar or 0 for unipolar.
Example
  if( Stepper_GetBipolar(1) )
  {
    // stepper 1 is bipolar
  }
  else
  {
    // stepper 1 is unipolar
  }

Definition at line 491 of file stepper.c.

int Stepper_GetDuty ( int  index  ) 

Get the duty Read the value previously set for the duty.

Parameters:
index An integer specifying which stepper (0 or 1).
Returns:
The duty (0 - 1023), or 0 on error.
Example
  int step1_duty = Stepper_GetDuty(1);
  // step1_duty has the current duty for stepper 1

Definition at line 435 of file stepper.c.

int Stepper_GetHalfStep ( int  index  ) 

Read whether the stepper is in half stepping mode or not.

Parameters:
index An integer specifying which stepper (0 or 1).
Returns:
the HalfStep setting.
Example
  if( Stepper_GetHalfStep(1) )
  {
    // stepper 1 is in half step mode
  }
  else
  {
    // stepper 1 is in full step mode
  }

Definition at line 546 of file stepper.c.

int Stepper_GetPosition ( int  index  ) 

Read the current position of a stepper motor.

Parameters:
index An integer specifying which stepper (0 or 1).
Returns:
The position, 0 on error.
Example
  int step0_pos = Stepper_GetPosition(0);
  // now step0_pos has the current position of stepper 0

Definition at line 327 of file stepper.c.

int Stepper_GetPositionRequested ( int  index  ) 

Read the destination position of a stepper motor.

This indicates where the stepper is ultimately headed. To see where it actually is, see Stepper_GetPosition().

Parameters:
index An integer specifying which stepper (0 or 1).
Returns:
The position and 0 on error
Example
  int step1_destination = Stepper_GetPositionRequested(1);
  // step1_destination has the requested position for stepper 1

Definition at line 351 of file stepper.c.

int Stepper_GetSpeed ( int  index  ) 

Get the speed at which a stepper will move.

Read the value previously set for the speed parameter.

Parameters:
index An integer specifying which stepper (0 or 1).
Returns:
The speed (0 - 1023), or 0 on error.
Example
  int step0_speed = Stepper_GetSpeed(0);
  // now step0_speed has the speed of stepper 0

Definition at line 305 of file stepper.c.

int Stepper_SetActive ( int  index,
int  state 
)

Sets whether the specified Stepper is active.

Parameters:
index An integer specifying which stepper (0 or 1).
state An integer specifying the active state - 1 (active) or 0 (inactive).
Returns:
Zero on success.
Example
  // enable stepper 1
  Stepper_SetActive(1, 1);

Definition at line 128 of file stepper.c.

int Stepper_SetBipolar ( int  index,
int  bipolar 
)

Declare whether the stepper is bipolar or not.

Default is bipolar.

Parameters:
index An integer specifying which stepper (0 or 1).
bipolar An integer 1 for bipolar, 0 for unipolar
Returns:
status (0 = OK).
Example
  // set stepper 1 to unipolar
  Stepper_SetBipolar(1, 0);

Definition at line 459 of file stepper.c.

int Stepper_SetDuty ( int  index,
int  duty 
)

Set the duty - from 0 to 1023.

The default is for 100% power (1023).

Parameters:
index An integer specifying which stepper (0 or 1).
duty An integer specifying the stepper duty (0 - 1023).
Returns:
status (0 = OK).
Example
  // set stepper 0 to half power
  Stepper_SetDuty(0, 512);

Definition at line 404 of file stepper.c.

int Stepper_SetHalfStep ( int  index,
int  halfStep 
)

Declare whether the stepper is in half stepping mode or not.

Default is not - i.e. in full step mode.

Parameters:
index An integer specifying which stepper (0 or 1).
halfStep An integer specifying 1 for half step, 0 for full step
Returns:
status (0 = OK).
Example
  // set stepper 1 to half step mode
  Stepper_SetHalfStep(1, 1);

Definition at line 515 of file stepper.c.

int Stepper_SetPosition ( int  index,
int  position 
)

Set the position of the specified stepper motor.

Note that this will not ask the stepper to move. It will simply update the position that the stepper thinks its at. To move the stepper, see Stepper_SetPositionRequested() or Stepper_Step().

Parameters:
index An integer specifying which stepper (0 or 1).
position An integer specifying the stepper position.
Returns:
status (0 = OK).
Example
  // reset stepper 1 to call its current position 0
  Stepper_SetPosition(1, 0);

Definition at line 202 of file stepper.c.

int Stepper_SetPositionRequested ( int  index,
int  positionRequested 
)

Set the destination position for a stepper motor.

This will start the stepper moving the given number of steps at the current speed, as set by Stepper_SetSpeed().

While it's moving, you can call Stepper_GetPosition() to read its current position.

Parameters:
index An integer specifying which stepper (0 or 1).
positionRequested An integer specifying the desired stepper position.
Returns:
status (0 = OK).
Example
  // start moving stepper 0 1500 steps
  Stepper_SetPositionRequested(0, 1500);

Definition at line 239 of file stepper.c.

int Stepper_SetSpeed ( int  index,
int  speed 
)

Set the speed at which a stepper will move.

This is a number of ms per step, rather than the more common steps per second. Arranging it this way makes it easier to express as an integer. Fastest speed is 1ms / step (1000 steps per second) and slowest is many seconds.

Parameters:
index An integer specifying which stepper (0 or 1).
speed An integer specifying the stepper speed in ms per step
Returns:
status (0 = OK).
Example
  // set the speed to 1ms / step (1000 steps per second)
  Stepper_SetSpeed(0, 1);

Definition at line 272 of file stepper.c.

int Stepper_Step ( int  index,
int  steps 
)

Simply take a number of steps from wherever the motor is currently positioned.

This function will move the motor a given number of steps from the current position.

Parameters:
index An integer specifying which stepper (0 or 1).
steps An integer specifying the number of steps. Can be negative to go in reverse.
Returns:
status (0 = OK).
Example
  // take 1200 steps forward from our current position
  Stepper_Step(0, 1200);

Definition at line 375 of file stepper.c.