OIStepper - Module to control stepper motor

Description

OIStepper is our module to drive two stepper motors synchronously. The idea of this module API is to give you full control of our motors with all functions available on our controller. Follow the Example section and our Projects section to see complete project based on stepper motors.

Example

#include "OpenIndus.h"
#include "Arduino.h"

void setup()
{
    Serial.begin(115200);

    Stepper.ledOn(LED_CYAN);

    /* Config sensor and move to this position */
    Stepper.attachLimitSwitch(ETOR1, DEVICE1);
    Stepper.cmdGoUntil(DEVICE1, ACTION_RESET, FORWARD, 33554);
}

void loop()
{
    delay(1000);
}

Functions

inline int OIStepper::getEtorLevel(Etor_t etor)

Warning

doxygenfunction: Cannot find function “OIStepper::attachEtorInterrupt” in doxygen xml output for project “OI-Library” from directory: ./../build/xml/

inline void OIStepper::attachBusyInterrupt(void (*callback)(void))

Attaches a user callback to the busy Interrupt The call back will be then called each time the busy pin is set or reset.

Parameters

callback[in] Name of the callback to attach to the Busy Interrupt

Returns

None

inline void OIStepper::attachErrorHandler(void (*callback)(uint16_t))

Attaches a user callback to the error Handler. The call back will be then called each time the library detects an error.

Parameters

callback[in] Name of the callback to attach to the error Hanlder

Returns

None

inline void OIStepper::attachFlagInterrupt(void (*callback)(void))

Attaches a user callback to the flag Interrupt The call back will be then called each time the status flag pin will be pulled down due to the occurrence of a programmed alarms ( OCD, thermal pre-warning or shutdown, UVLO, wrong command, non-performable command)

Parameters

callback[in] Name of the callback to attach to the Flag Interrupt

Returns

None

inline uint8_t OIStepper::checkBusyHw(void) const

Checks if at least one OIStepper is busy by checking busy pin position. The busy pin is shared between all devices.

Returns

One if at least one OIStepper is busy, otherwise zero

inline uint8_t OIStepper::checkStatusHw(void) const

Checks if at least one OIStepper has an alarm flag set by reading flag pin position. The flag pin is shared between all devices.

Returns

One if at least one OIStepper has an alarm flag set , otherwise zero

inline uint16_t OIStepper::cmdGetStatus(uint8_t deviceId) const

Issues OIStepper Get Status command.

Parameters

deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

Returns

Status Register content

inline void OIStepper::cmdGoHome(uint8_t deviceId) const

Issues OIStepper Go Home command (Shortest path to zero position)

Parameters

deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

Returns

None

inline void OIStepper::cmdGoMark(uint8_t deviceId) const

Issues OIStepper Go Mark command.

Parameters

deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

Returns

None

inline void OIStepper::cmdGoTo(uint8_t deviceId, int32_t abs_pos) const

Issues OIStepper Go To command.

Parameters
  • deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

  • abs_pos[in] absolute position in steps in agreement with the step mode where requested to move

Returns

None

inline void OIStepper::cmdGoToDir(uint8_t deviceId, motorDir_t direction, int32_t abs_pos) const

Issues OIStepper Go To Dir command.

Parameters
  • deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

  • direction[in] movement direction

  • abs_pos[in] absolute position in steps in agreement with the step mode where requested to move

Returns

None

inline void OIStepper::cmdGoUntil(uint8_t deviceId, motorAction_t action, motorDir_t direction, uint32_t speed) const

Issues OIStepper Go Until command.

Parameters
  • deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

  • action[in] ACTION_RESET or ACTION_COPY

  • direction[in] movement direction

  • speed[in] in 2^-28 step/tick

Returns

None

inline void OIStepper::cmdHardHiZ(uint8_t deviceId) const

Issues OIStepper Hard HiZ command.

Note

The HardHiZ command immediately disables the power bridges (high impedance state) and raises the HiZ flag. When the motor is stopped, a HardHiZ command forces the bridges to enter high impedance state. This command can be given anytime and is immediately executed.

Parameters

deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

Returns

None

inline void OIStepper::cmdHardStop(uint8_t deviceId) const

Issues OIStepper Hard Stop command.

Note

The HardStop command causes an immediate motor stop with infinite deceleration. When the motor is in high impedance state, a HardStop command forces the bridges to exit high impedance state; no motion is performed. This command can be given anytime and is immediately executed. This command keeps the BUSY flag low until the motor is stopped.

Parameters

deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

Returns

None

inline void OIStepper::cmdMove(uint8_t deviceId, motorDir_t direction, uint32_t n_step) const

Issues OIStepper Move command.

Parameters
  • deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

  • direction[in] Movement direction

  • n_step[in] number of steps

Returns

None

inline void OIStepper::cmdReleaseSw(uint8_t deviceId, motorAction_t action, motorDir_t direction) const

Issues OIStepper Release SW command.

Parameters
  • deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

  • action[in] type of action to undertake when the SW input is forced high

  • direction[in] movement direction

Returns

None

inline void OIStepper::cmdResetDevice(uint8_t deviceId) const

Issues OIStepper Reset Device command.

Parameters

deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

Returns

None

inline void OIStepper::cmdResetPos(uint8_t deviceId) const

Issues OIStepper Reset Pos command.

Parameters

deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

Returns

None

inline void OIStepper::cmdRun(uint8_t deviceId, motorDir_t direction, uint32_t speed) const

Issues OIStepper Run command.

Parameters
  • deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

  • direction[in] Movement direction (FORWARD, BACKWARD)

  • speed[in] in 2^-28 step/tick

Returns

None

inline void OIStepper::cmdSoftHiZ(uint8_t deviceId) const

Issues OIStepper Soft HiZ command.

Note

The SoftHiZ command disables the power bridges (high impedance state) after a deceleration to zero. The deceleration value used is the one stored in the DEC register. When bridges are disabled, the HiZ flag is raised. When the motor is stopped, a SoftHiZ command forces the bridges to enter high impedance state. This command can be given anytime and is immediately executed. This command keeps the BUSY flag low until the motor is stopped.

Parameters

deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

Returns

None

inline void OIStepper::cmdSoftStop(uint8_t deviceId) const

Issues OIStepper Soft Stop command.

Note

The SoftStop command causes an immediate deceleration to zero speed and a consequent motor stop. The deceleration value used is the one stored in the DEC register. When the motor is in high impedance state, a SoftStop command forces the bridges to exit from high impedance state. No motion is performed. This command can be given anytime and is immediately executed. This command keeps the BUSY flag low until the motor is stopped.

Parameters

deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

Returns

None

inline void OIStepper::cmdStepClock(uint8_t deviceId, motorDir_t direction) const

Issues OIStepper Step Clock command.

Parameters
  • deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

  • direction[in] Movement direction (FORWARD, BACKWARD)

Returns

None

inline void OIStepper::fetchAndClearAllStatus(void) const

Fetch and clear status flags of all devices by issuing a GET_STATUS command simultaneously

to all devices. Then, the fetched status of each device can be retrieved by using the GetFetchedStatus function provided there is no other calls to functions which use the SPI in between.

Returns

None

inline int32_t OIStepper::getMark(uint8_t deviceId) const

Returns the mark position of the specified device.

Parameters

deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

Returns

Mark register value converted in a 32b signed integer

inline int32_t OIStepper::getPosition(uint8_t deviceId) const

Returns the ABS_POSITION of the specified device.

Parameters

deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

Returns

ABS_POSITION register value converted in a 32b signed integer

inline bool OIStepper::isDeviceBusy(uint8_t deviceId) const

Checks if the specified device is busy by reading the Busy flag bit ot its status Register.

Parameters

deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

Returns

true if device is busy, false zero

inline uint16_t OIStepper::readStatusRegister(uint8_t deviceId) const

Reads the Status Register value.

Note

The status register flags are not cleared at the difference with CmdGetStatus()

Parameters

deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

Returns

Status register value

inline void OIStepper::releaseReset(uint8_t deviceId) const

Releases the OIStepper reset (pin set to High) of all devices.

Parameters

deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

Returns

None

inline void OIStepper::reset(uint8_t deviceId) const

Resets the OIStepper (reset pin set to low) of all devices.

Parameters

deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

Returns

None

inline bool OIStepper::selectStepMode(uint8_t deviceId, motorStepMode_t stepMode) const

Set the stepping mode.

Parameters
  • deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

  • stepMode[in] from full step to 1/128 microstep as specified in enum motorStepMode_t

Returns

TRUE if successfull, FALSE if failure

inline void OIStepper::sendQueuedCommands(void) const

Sends commands stored previously in the queue by QueueCommands.

Returns

None

inline void OIStepper::setHome(uint8_t deviceId, int32_t homePos) const

Sets Home Position (ABS pos set to current pos minus new home position)

Parameters
  • deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

  • homePos[in] new home position

Returns

None

inline void OIStepper::setMark(uint8_t deviceId, int32_t markPos) const

Sets Mark position.

Parameters
  • deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

  • markPos[in] new mark position

Returns

None

inline void OIStepper::startStepClock(uint16_t newFreq) const

Start the step clock by using the given frequency.

Note

The frequency is directly the current speed of the device

Parameters

newFreq[in] in Hz of the step clock

Returns

None

inline void OIStepper::stopStepClock(void) const

Stops the PWM uses for the step clock.

Returns

None

inline void OIStepper::waitForAllDevicesNotBusy(void) const

Locks until all devices become not busy.

Returns

None

inline void OIStepper::waitWhileActive(uint8_t deviceId) const

Locks until the device becomes not busy.

Parameters

deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

Returns

None

inline void OIStepper::cmdSetParam(uint8_t deviceId, uint32_t param, uint32_t value) const

Issues the SetParam command to the OIStepper of the specified device.

Parameters
  • deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

  • param[in] Register adress (Powerstep01_ABS_POS, Powerstep01_MARK,…)

  • value[in] Value to set in the register

Returns

None

inline uint32_t OIStepper::cmdGetParam(uint8_t deviceId, uint32_t param) const

Issues OIStepper Get Param command.

Parameters
  • deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

  • param[in] OIStepper register address

Returns

Register value - 1 to 3 bytes (depends on register)

inline void OIStepper::setAnalogValue(uint8_t deviceId, uint32_t param, float value) const

Issues the SetParam command to the OIStepper of the specified device.

Parameters
  • deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

  • param[in] Register adress (Powerstep01_ABS_POS, Powerstep01_MARK,…)

  • value[in] Floating point value to convert and set into the register

Returns

TRUE if param and value are valid, FALSE otherwise

inline float OIStepper::getAnalogValue(uint8_t deviceId, uint32_t param) const

Issues OIStepper Get Parameter command and convert the result to floating point if meaningfull.

Parameters
  • deviceId[in] (from 0 to MAX_NUMBER_OF_DEVICES-1 )

  • param[in] Powerstep01 register address

Returns

Register value - 1 to 3 bytes (depends on register)