Biblioteca com go_angle

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

StepperMotor Class Reference

StepperMotor Class Reference

Stepper Motor control class. More...

#include <StepperMotor.h>

Public Types

enum  RotMode { SHORTEST, NO_WRAPAROUND, CLOCKWISE_ONLY, COUNTER_CLOCKWISE_ONLY }
 

Constants for motor rotate mode.

More...
enum  SyncMode { ASYNCHRONOUS, SYNCHRONOUS }
 

Constants for syncronization mode.

More...
enum  PositionDetectPorarity { RISING_EDGE, FALLING_EDGE }
 

Constants for position detection edge polarity.

More...

Public Member Functions

 StepperMotor (PinName out_A=P0_23, PinName out_B=P1_02, PinName out_PWR=P0_13, PinName position_detect=P0_15)
 Create a stepper motor object connected to specified DigitalOut pins and a DigitalIn pin.
int set_pps (int v)
 Set the pulse width (i.e.
void set_max_pps (int v)
 Set maximum PPS (= minimum pulse width) which will be used in finding home position.
int find_home_position (PositionDetectPorarity edge)
 Find home position: rotate the motor until the detection edge comes.
void set_home_position (void)
 Update home position.
int go_position (int v)
 Turn the motor to defined position (by steps from home position)
void go_angle (float angle)
 Turn the motor to defined position (by angle (0.0..360 degree) from home position)
int move_steps (int s)
 Turn the motor to defined position (by steps from current position)
void set_rot_mode (RotMode m)
 Interface for motor rotate mode setting.
void set_sync_mode (SyncMode m)
 Interface for syncronization mode setting.
int distance (void)
 Check remaining distance that motor need to move.
void set_pause (int sw)
 Pause/Resume the motor action.
void set_power_ctrl (int sw)
 Auto power control enable.
void set_steps_per_rotate (int steps)
 Setting for steps/rotate.

Detailed Description

Stepper Motor control class.

Example:

  #include "mbed.h"
  #include "StepperMotor.h"

  StepperMotor m( p21, p22, p23, p24 );

  int main() {
      m.set_sync_mode( StepperMotor::SYNCHRONOUS );
      m.set_power_ctrl( true );

      while( 1 ) {
          m.go_angle( 120 );
          wait( 0.5 );
     
          m.go_angle( 240 );
          wait( 0.5 );
   
          m.go_angle( 0 );
          wait( 0.5 ); 

          m.go_angle( 240 );
          wait( 0.5 );
     
          m.go_angle( 120 );
          wait( 0.5 );
   
          m.go_angle( 0 );
          wait( 0.5 ); 
      }
  }

Definition at line 52 of file StepperMotor.h.


Member Enumeration Documentation

Constants for position detection edge polarity.

Enumerator:
RISING_EDGE 

position detection done by rising edge

FALLING_EDGE 

position detection done by falling edge

Definition at line 70 of file StepperMotor.h.

enum RotMode

Constants for motor rotate mode.

Enumerator:
SHORTEST 

turn by shortest direction

NO_WRAPAROUND 

do not accross home position

CLOCKWISE_ONLY 

one-way: clockwise turn

COUNTER_CLOCKWISE_ONLY 

one-way: counter clockwise turn

Definition at line 56 of file StepperMotor.h.

enum SyncMode

Constants for syncronization mode.

Enumerator:
ASYNCHRONOUS 

program does wait motor turn completion

SYNCHRONOUS 

program doesn't wait motor turn completion

Definition at line 64 of file StepperMotor.h.


Constructor & Destructor Documentation

StepperMotor ( PinName  out_A = P0_23,
PinName  out_B = P1_02,
PinName  out_PWR = P0_13,
PinName  position_detect = P0_15 
)

Create a stepper motor object connected to specified DigitalOut pins and a DigitalIn pin.

Parameters:
out_ADigitalOut pin for motor pulse signal-A
out_BDigitalOut pin for motor pulse signal-B
out_PWRDigitalOut pin for TA7774's power control (option)
position_detectDigitalIn pin for home position detection (option)

Definition at line 4 of file StepperMotor.cpp.


Member Function Documentation

int distance ( void   )

Check remaining distance that motor need to move.

software can check if the motor action completed in asynchronous mode

Returns:
remaining steps that motor need to go

Definition at line 125 of file StepperMotor.cpp.

int find_home_position ( PositionDetectPorarity  edge )

Find home position: rotate the motor until the detection edge comes.

Turns the motor until the home position detected. The "home position" is a reference point for the step and angle. It will be step=0 and angle=0. The detection signal edge can be defined by an argument. It follows the rotate mode. When the edge is detected, the motor will be stopped and it will be the new home position. If no detection signal detected, no home position update done.

Parameters:
edgedefines detection edge rise or fall

Definition at line 42 of file StepperMotor.cpp.

void go_angle ( float  angle )

Turn the motor to defined position (by angle (0.0..360 degree) from home position)

Make motor move to absolute position

Parameters:
vthe position defined by steps from home position

Definition at line 108 of file StepperMotor.cpp.

int go_position ( int  v )

Turn the motor to defined position (by steps from home position)

Make motor move to absolute position

Parameters:
vthe position defined by steps from home position

Definition at line 103 of file StepperMotor.cpp.

int move_steps ( int  s )

Turn the motor to defined position (by steps from current position)

Make motor move to defined position

Parameters:
vthe position defined by steps from home position

Definition at line 112 of file StepperMotor.cpp.

void set_home_position ( void   )

Update home position.

Set the home position as current motor position.

Definition at line 95 of file StepperMotor.cpp.

void set_max_pps ( int  v )

Set maximum PPS (= minimum pulse width) which will be used in finding home position.

Parameters:
vmaximum pulse per second : default is 100. lower number makes the turn slower

Definition at line 38 of file StepperMotor.cpp.

void set_pause ( int  sw )

Pause/Resume the motor action.

Parameters:
swuse "true" for pause, "false" for resume

Definition at line 129 of file StepperMotor.cpp.

void set_power_ctrl ( int  sw )

Auto power control enable.

If the auto power control is enabled, the motor power will be turned-off when it stays same place

Parameters:
swuse "true" for pause, "false" for resume

Definition at line 141 of file StepperMotor.cpp.

int set_pps ( int  v )

Set the pulse width (i.e.

motor turning speed)

Parameters:
vpulse per second : default is 100. lower number makes the turn slower

Definition at line 28 of file StepperMotor.cpp.

void set_rot_mode ( RotMode  m )

Interface for motor rotate mode setting.

Example:

  StepperMotor    m( p21, p22, p23, p24 );
  int main() {
      m.set_rot_mode( StepperMotor::NO_WRAPAROUND );
      ...
Parameters:
mmotor rotate mode : SHORTEST, NO_WRAPAROUND, CLOCKWISE_ONLY or COUNTER_CLOCKWISE_ONLY

Definition at line 117 of file StepperMotor.cpp.

void set_steps_per_rotate ( int  steps )

Setting for steps/rotate.

This parameter is required if program want to use the "go_angle()" interface. The angle will be calculated from this parameter.

Parameters:
stepsper rotate

Definition at line 145 of file StepperMotor.cpp.

void set_sync_mode ( SyncMode  m )

Interface for syncronization mode setting.

Example:

  StepperMotor    m( p21, p22, p23, p24 );
  int main() {
      m.set_sync_mode( StepperMotor::NO_WRAPAROUND );
      ...
Parameters:
mmotor rotate mode : ASYNCHRONOUS or SYNCHRONOUS

Definition at line 121 of file StepperMotor.cpp.