Bioscara
DALSA's DIY SCARA Robot Arm.
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
bioscara_hardware_drivers::MockJoint Class Reference

Representing a single joint mocking the hardware joint. More...

#include <mMockJoint.h>

Inheritance diagram for bioscara_hardware_drivers::MockJoint:
bioscara_hardware_drivers::BaseJoint

Public Member Functions

 MockJoint (const std::string name)
 
err_type_t enable (u_int8_t driveCurrent, u_int8_t holdCurrent) override
 Engages the joint.
 
err_type_t disable (void) override
 disenganges the joint
 
err_type_t getPosition (float &pos) override
 get the current joint position in radians or m for cylindrical and prismatic joints respectively.
 
err_type_t setPosition (float pos) override
 get the current joint position in radians or m for cylindrical and prismatic joints respectively.
 
err_type_t getVelocity (float &vel) override
 get the current joint velocity in radians/s or m/s for cylindrical and prismatic joints respectively.
 
err_type_t setVelocity (float vel) override
 Set the current joint velocity in radians/s or m/s for cylindrical and prismatic joints respectively.
 
err_type_t checkOrientation (float angle=2.0) override
 Calls the checkOrientation method of the motor. Checks in which direction the motor is turning.
 
err_type_t stop (void) override
 Stops the motor.
 
err_type_t getFlags (void) override
 Overload of getFlags(u_int8_t &flags)
 
bool isHomed (void) override
 Checks the state if the motor is homed.
 
- Public Member Functions inherited from bioscara_hardware_drivers::BaseJoint
 BaseJoint (const std::string name)
 Create a Joint object.
 
 ~BaseJoint (void)
 Destroy the BaseJoint object.
 
virtual err_type_t init (void)
 Initialize the joint communication.
 
virtual err_type_t deinit (void)
 Denitialize the joint communication.
 
virtual err_type_t home (float velocity, u_int8_t sensitivity, u_int8_t current)
 Blocking implementation to home the joint.
 
virtual err_type_t startHoming (float velocity, u_int8_t sensitivity, u_int8_t current)
 non-blocking implementation to home the joint
 
virtual err_type_t postHoming (void)
 perform tasks after a non-blocking homing
 
virtual err_type_t moveSteps (int32_t steps)
 Move full steps.
 
virtual err_type_t disableCL (void)
 
virtual err_type_t setDriveCurrent (u_int8_t current)
 Set the Drive Current.
 
virtual err_type_t setHoldCurrent (u_int8_t current)
 Set the Hold Current.
 
virtual err_type_t setBrakeMode (u_int8_t mode)
 Set Brake Mode.
 
virtual err_type_t setMaxAcceleration (float maxAccel)
 Set the maximum permitted joint acceleration (and deceleration) in rad/s^2 or m/s^2 for cylindrical and prismatic joints respectively.
 
virtual err_type_t setMaxVelocity (float maxVel)
 Set the maximum permitted joint velocity in rad/s or m/s for cylindrical and prismatic joints respectively.
 
virtual err_type_t enableStallguard (u_int8_t sensitivity)
 Enable encoder stall detection of the joint.
 
virtual bool isEnabled (void)
 Checks the state if the motor is enabled.
 
virtual bool isStalled (void)
 Checks if the motor is stalled.
 
virtual bool isBusy (void)
 Checks if the joint controller is busy processing a blocking command.
 
virtual err_type_t getFlags (u_int8_t &flags)
 get the latest driver state flags from the joint
 
virtual stp_reg_t getCurrentBCmd (void)
 get the currently active blocking command
 

Protected Member Functions

err_type_t _home (float velocity, u_int8_t sensitivity, u_int8_t current)
 Call to start the homing sequence of a joint.
 
- Protected Member Functions inherited from bioscara_hardware_drivers::BaseJoint
virtual void wait_while_busy (const float period_ms)
 Blocking loop waiting for BUSY flag to reset.
 

Private Member Functions

float getDeltaT (std::chrono::_V2::system_clock::time_point &last_call, bool update=true)
 Compute the time since the given time point.
 

Private Attributes

float q = 0.0
 position
 
float qd = 0.0
 velocity
 
std::chrono::_V2::system_clock::time_point last_set_position = std::chrono::high_resolution_clock::now()
 
std::chrono::_V2::system_clock::time_point last_set_velocity = last_set_position
 
std::chrono::_V2::system_clock::time_point async_start_time = last_set_position
 
stp_reg_t op_mode = NONE
 

Additional Inherited Members

- Public Types inherited from bioscara_hardware_drivers::BaseJoint
enum  stp_reg_t {
  NONE = 0x00 , PING = 0x0f , SETUP = 0x10 , SETRPM = 0x11 ,
  GETDRIVERRPM = 0x12 , MOVESTEPS = 0x13 , MOVEANGLE = 0x14 , MOVETOANGLE = 0x15 ,
  GETMOTORSTATE = 0x16 , RUNCOTINOUS = 0x17 , ANGLEMOVED = 0x18 , SETCURRENT = 0x19 ,
  SETHOLDCURRENT = 0x1A , SETMAXACCELERATION = 0x1B , SETMAXDECELERATION = 0x1C , SETMAXVELOCITY = 0x1D ,
  ENABLESTALLGUARD = 0x1E , DISABLESTALLGUARD = 0x1F , CLEARSTALL = 0x20 , SETBRAKEMODE = 0x22 ,
  ENABLEPID = 0x23 , DISABLEPID = 0x24 , ENABLECLOSEDLOOP = 0x25 , DISABLECLOSEDLOOP = 0x26 ,
  SETCONTROLTHRESHOLD = 0x27 , MOVETOEND = 0x28 , STOP = 0x29 , GETPIDERROR = 0x2A ,
  CHECKORIENTATION = 0x2B , GETENCODERRPM = 0x2C , HOME = 0x2D , HOMEOFFSET = 0x2E
}
 register and command definitions More...
 
- Public Attributes inherited from bioscara_hardware_drivers::BaseJoint
std::string name
 Joint name for logging.
 
- Protected Attributes inherited from bioscara_hardware_drivers::BaseJoint
u_int8_t flags = 0b00001100
 State flags transmitted with every I2C transaction.
 
stp_reg_t current_b_cmd = NONE
 Keeps track if a blocking command is being executed.
 

Detailed Description

Representing a single joint mocking the hardware joint.

This mock hardware implementation simply mirrors (potentially delayed) commands.

Note
Much of this implementation is very basic not well written.

Constructor & Destructor Documentation

◆ MockJoint()

bioscara_hardware_drivers::MockJoint::MockJoint ( const std::string  name)

Member Function Documentation

◆ _home()

err_type_t bioscara_hardware_drivers::MockJoint::_home ( float  velocity,
u_int8_t  sensitivity,
u_int8_t  current 
)
protectedvirtual

Call to start the homing sequence of a joint.

The joint will start rotating with the specified speed until a resistance which drives the PID error above the specified threshold is encountered. At this point the stepper stops and zeros the encoder.

Parameters
velocitysigned velocity in rad/s or m/s. Must be between 1.0 < RAD2DEG(JOINT2ACTUATOR(velocity, reduction, 0)) / 6 < 250.0
sensitivityEncoder pid error threshold 0 to 255.
currenthoming current, determines how easy it is to stop the motor and thereby provoke a stall
Returns
err_type_t

Implements bioscara_hardware_drivers::BaseJoint.

◆ checkOrientation()

err_type_t bioscara_hardware_drivers::MockJoint::checkOrientation ( float  angle = 2.0)
overridevirtual

Calls the checkOrientation method of the motor. Checks in which direction the motor is turning.

Note
This is a blocking function.
Parameters
angledegrees how much the motor should turn. A few degrees is sufficient.
Returns
err_type_t

Reimplemented from bioscara_hardware_drivers::BaseJoint.

◆ disable()

err_type_t bioscara_hardware_drivers::MockJoint::disable ( void  )
overridevirtual

disenganges the joint

invokes stop(), sets hold and drive current to 0 and sets the the joint brake mode to freewheeling

Returns
err_type_t

Reimplemented from bioscara_hardware_drivers::BaseJoint.

◆ enable()

err_type_t bioscara_hardware_drivers::MockJoint::enable ( u_int8_t  driveCurrent,
u_int8_t  holdCurrent 
)
overridevirtual

Engages the joint.

This function prepares the motor for movement. After successfull execution the joint is ready to accept setPosition() and setVelocity() commands.

The function sets the drive and hold current for the specified joint and engages the motor. The currents are in percent of driver max. output (2.5A, check with TMC5130 datasheet or Ustepper documentation)

Parameters
driveCurrentdrive current in 0-100 % of 2.5A output (check uStepper doc.)
holdCurrenthold current in 0-100 % of 2.5A output (check uStepper doc.)
Returns
err_type_t

Reimplemented from bioscara_hardware_drivers::BaseJoint.

◆ getDeltaT()

float bioscara_hardware_drivers::MockJoint::getDeltaT ( std::chrono::_V2::system_clock::time_point &  last_call,
bool  update = true 
)
private

Compute the time since the given time point.

Parameters
last_callthe time point to calculate the duration
updateIf true compute the duration and also reset last_call to current time
Returns
elapsed time in seconds since last_call

◆ getFlags()

err_type_t bioscara_hardware_drivers::MockJoint::getFlags ( void  )
overridevirtual

Overload of getFlags(u_int8_t &flags)

Returns
err_type_t

Reimplemented from bioscara_hardware_drivers::BaseJoint.

◆ getPosition()

err_type_t bioscara_hardware_drivers::MockJoint::getPosition ( float &  pos)
overridevirtual

get the current joint position in radians or m for cylindrical and prismatic joints respectively.

Warning
If the joint is not homed this method does not return an error. Instead pos will be 0.0.
Parameters
posthe current joint position in rad or m.
Returns
err_type_t

Implements bioscara_hardware_drivers::BaseJoint.

◆ getVelocity()

err_type_t bioscara_hardware_drivers::MockJoint::getVelocity ( float &  vel)
overridevirtual

get the current joint velocity in radians/s or m/s for cylindrical and prismatic joints respectively.

Parameters
velthe current joint velocity in rad/s or m/s.
Returns
err_type_t

Implements bioscara_hardware_drivers::BaseJoint.

◆ isHomed()

bool bioscara_hardware_drivers::MockJoint::isHomed ( void  )
overridevirtual

Checks the state if the motor is homed.

Reads the internal state flags from the last transmission. If an update is neccessary call getFlags() before invoking this function.

Returns
true if the motor is homed, false if not.

Reimplemented from bioscara_hardware_drivers::BaseJoint.

◆ setPosition()

err_type_t bioscara_hardware_drivers::MockJoint::setPosition ( float  pos)
overridevirtual

get the current joint position in radians or m for cylindrical and prismatic joints respectively.

Parameters
posthe commanded joint position in rad or m.
Returns
err_type_t

Reimplemented from bioscara_hardware_drivers::BaseJoint.

◆ setVelocity()

err_type_t bioscara_hardware_drivers::MockJoint::setVelocity ( float  vel)
overridevirtual

Set the current joint velocity in radians/s or m/s for cylindrical and prismatic joints respectively.

Parameters
velthe commanded joint velocity in rad/s or m/s.
Returns
err_type_t

Reimplemented from bioscara_hardware_drivers::BaseJoint.

◆ stop()

err_type_t bioscara_hardware_drivers::MockJoint::stop ( void  )
overridevirtual

Stops the motor.

Stops the motor by setting the maximum velocity to zero and the position setpoint to the current position

Returns
err_type_t

Reimplemented from bioscara_hardware_drivers::BaseJoint.

Member Data Documentation

◆ async_start_time

std::chrono::_V2::system_clock::time_point bioscara_hardware_drivers::MockJoint::async_start_time = last_set_position
private

◆ last_set_position

std::chrono::_V2::system_clock::time_point bioscara_hardware_drivers::MockJoint::last_set_position = std::chrono::high_resolution_clock::now()
private

◆ last_set_velocity

std::chrono::_V2::system_clock::time_point bioscara_hardware_drivers::MockJoint::last_set_velocity = last_set_position
private

◆ op_mode

stp_reg_t bioscara_hardware_drivers::MockJoint::op_mode = NONE
private

◆ q

float bioscara_hardware_drivers::MockJoint::q = 0.0
private

position

◆ qd

float bioscara_hardware_drivers::MockJoint::qd = 0.0
private

velocity


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