UMRT Arm Firmware Library
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
ArduinoStepperController Class Reference

Manages the Firmata connection to an Arduino running the Stepper Controller program. More...

#include <arduino_stepper_controller.hpp>

Inheritance diagram for ArduinoStepperController:
Inheritance graph
[legend]
Collaboration diagram for ArduinoStepperController:
Collaboration graph
[legend]

Public Member Functions

 ArduinoStepperController ()
 Initializes an ArduinoStepperController.
 
 ~ArduinoStepperController () noexcept override
 Destroys an ArduinoStepperController.
 
bool sendEcho (const std::vector< uint8_t > &payload)
 Sends a SysexCommands::ARDUINO_ECHO command with the provided payload. More...
 
bool setSpeed (const uint8_t motor, const int16_t speed)
 Sends a SysexCommands::SET_SPEED command to set the speed of a motor. More...
 
bool getSpeed (const uint8_t motor)
 Sends a SysexCommands::GET_SPEED command to query the speed of a motor. More...
 
bool sendStep (const uint8_t motor, const uint16_t num_steps, const int16_t speed)
 Sends a SysexCommands::SEND_STEP command to move a motor a fixed number of steps. More...
 
bool seekPosition (const uint8_t motor, const int32_t position, const int16_t speed)
 Sends a SysexCommands::SEEK_POS command to move a motor to specific step position. More...
 
bool getPosition (const uint8_t motor)
 Sends a SysexCommands::GET_POS command to query the current position of a motor. More...
 
bool setGripper (const uint8_t position)
 Sends a SysexCommands::SET_GRIPPER command to set the target position of the gripper servo. More...
 
bool isSetup () const
 Returns whether the connection to the stepper controller Arduino has been fully established. More...
 

Public Attributes

boost::signals2::signal< void(void)> ESetup
 Boost signal triggered once this ArduinoStepperController is fully setup.
 
boost::signals2::signal< void(std::vector< uint8_t >)> EArduinoEcho
 Boost signal triggered when sendEcho responses are received.
 
boost::signals2::signal< void(uint8_t, int16_t)> ESetSpeed
 Boost signal triggered when setSpeed responses are received.
 
boost::signals2::signal< void(uint8_t, int16_t)> EGetSpeed
 Boost signal triggered when getSpeed responses are received.
 
boost::signals2::signal< void(uint8_t, uint16_t, int16_t)> ESendStep
 Boost signal triggered when sendStep responses are received.
 
boost::signals2::signal< void(uint8_t, int32_t, int16_t)> ESeekPosition
 Boost signal triggered when seekPosition responses are received.
 
boost::signals2::signal< void(uint8_t, int32_t)> EGetPosition
 Boost signal triggered when getPosition responses are received.
 
boost::signals2::signal< void(uint8_t)> ESetGripper
 Boost signal triggered when setGripper responses are received.
 

Protected Member Functions

void setupArduino (const int &version)
 Completes configuration of the Stepper Controller Arduino once a Firmata link has been established. More...
 
void handleSysex (const std::vector< unsigned char > &message)
 Handles System-Exclusive (Sysex) messages received on the Firmata link with the Stepper Controller Arduino. More...
 

Protected Attributes

boost::signals2::connection connectionInitialized
 Boost signal triggered when the initial Firmata connection is established. More...
 

Signal Processing Helper Functions

Helper functions for decoding the parameters of Sysex commands processed by handleSysex before forwarding to their associated signal.

Parameters
messagethe de-firmatified Sysex payload
void handleEArduinoEcho (const std::vector< unsigned char > &message)
 
void handleESetSpeed (const std::vector< unsigned char > &message)
 
void handleEGetSpeed (const std::vector< unsigned char > &message)
 
void handleESendStep (const std::vector< unsigned char > &message)
 
void handleESeekPosition (const std::vector< unsigned char > &message)
 
void handleEGetPosition (const std::vector< unsigned char > &message)
 
void handleESetGripper (const std::vector< unsigned char > &message)
 

Detailed Description

Manages the Firmata connection to an Arduino running the Stepper Controller program.

Responses are conveyed through Boost signals.

Member Function Documentation

◆ getPosition()

bool ArduinoStepperController::getPosition ( const uint8_t  motor)

Sends a SysexCommands::GET_POS command to query the current position of a motor.

Parameters
motorthe ID of the motor to query
Returns
true if successfully written to the serial connection

◆ getSpeed()

bool ArduinoStepperController::getSpeed ( const uint8_t  motor)

Sends a SysexCommands::GET_SPEED command to query the speed of a motor.

Response callbacks are available through EGetSpeed.

Parameters
motorthe ID of the motor to query
Returns
true if successfully written to the serial connection

◆ handleSysex()

void ArduinoStepperController::handleSysex ( const std::vector< unsigned char > &  message)
protected

Handles System-Exclusive (Sysex) messages received on the Firmata link with the Stepper Controller Arduino.

Parameters
messagethe message payload

◆ isSetup()

bool ArduinoStepperController::isSetup ( ) const

Returns whether the connection to the stepper controller Arduino has been fully established.

Returns
true if so

◆ seekPosition()

bool ArduinoStepperController::seekPosition ( const uint8_t  motor,
const int32_t  position,
const int16_t  speed 
)

Sends a SysexCommands::SEEK_POS command to move a motor to specific step position.

Since this command seeks a position, the sign of the speed is ignored.

Parameters
motorthe ID of the motor to move
positionthe target position in number of steps from the motor's zero point
speedthe signed target speed to move the motor at, in 1/10 RPM. Note that the absolute value is taken.
Returns
true if successfully written to the serial connection

◆ sendEcho()

bool ArduinoStepperController::sendEcho ( const std::vector< uint8_t > &  payload)

Sends a SysexCommands::ARDUINO_ECHO command with the provided payload.

Response callbacks are available through EArduinoEcho.

Parameters
payloadbyte vector to echo off the Stepper Controller Arduino
Returns
true if successfully written to the serial connection

◆ sendStep()

bool ArduinoStepperController::sendStep ( const uint8_t  motor,
const uint16_t  num_steps,
const int16_t  speed 
)

Sends a SysexCommands::SEND_STEP command to move a motor a fixed number of steps.

Direction is controlled by the sign of the target speed. Response callbacks are available through ESendStep.

Parameters
motorthe ID of the motor to move
num_stepsthe number of steps to move
speedthe signed target speed to move the motor at, in 1/10 RPM
Returns
true if successfully written to the serial connection

◆ setGripper()

bool ArduinoStepperController::setGripper ( const uint8_t  position)

Sends a SysexCommands::SET_GRIPPER command to set the target position of the gripper servo.

Response callbacks are available through ESetGripper.

Parameters
positionthe target servo angle, mapped to [0, 180]
Returns
true if successfully written to the serial connection

◆ setSpeed()

bool ArduinoStepperController::setSpeed ( const uint8_t  motor,
const int16_t  speed 
)

Sends a SysexCommands::SET_SPEED command to set the speed of a motor.

Response callbacks are available through ESetSpeed.

Parameters
motorthe ID of the motor to control
speedthe signed target speed to set the motor to, in 1/10 RPM
Returns
true if successfully written to the serial connection

◆ setupArduino()

void ArduinoStepperController::setupArduino ( const int &  version)
protected

Completes configuration of the Stepper Controller Arduino once a Firmata link has been established.

Parameters
versionthe Firmata version supplied with the connectionInitialized response

Member Data Documentation

◆ connectionInitialized

boost::signals2::connection ArduinoStepperController::connectionInitialized
protected

Boost signal triggered when the initial Firmata connection is established.

Should immediately call setupArduino.


The documentation for this class was generated from the following files: