Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laelaps::LaeKinematics Class Reference

Laelaps kinematics class. More...

#include <laeKin.h>

Public Member Functions

 LaeKinematics ()
 Default initializer constructor.
 
virtual ~LaeKinematics ()
 Desctructor.
 
int open (const std::string &strDevMotorCtlrs, const int nBaudRate, int(*fnEnable)(void *, bool)=NULL, void *pEnableArg=NULL)
 Open communication with the Laelaps motor controllers. More...
 
virtual int close ()
 Close communication. More...
 
virtual bool isOpen ()
 Test if connection is open. More...
 
virtual bool isEnabled ()
 Test if motors are enabled. More...
 
virtual bool areMotorsPowered ()
 Test if motors are powered. More...
 
virtual int configure (const LaeDesc &desc)
 Configure kinematics chains and data from product description. More...
 
virtual int configure (const LaeTunes &tunes)
 Configure kinematics for operation. More...
 
virtual int reload (const LaeTunes &tunes)
 Reload configuration tuning parameters. More...
 
LaePlatformgetPlatform ()
 Get robot platform kinodynamics. More...
 
motor::roboclaw::RoboClawgetMotorCtlr (const int nMotorCtlrId)
 Get pointer to motor controller by name (key). More...
 
LaeMapPowertraingetPowertrainMap ()
 Get map of all powertrain kinodynamics. More...
 
LaePowertraingetPowertrain (const std::string &strName)
 Get pointer to powertrain by name (key). More...
 
LaePowertraingetPowertrain (int nCtlr, int nMotor)
 Get pointer to powertrain by controller id and motor index. More...
 
LaePowertraingetPowertrain (int nMotorId)
 Get pointer to powertrain by motor id. More...
 
virtual int getPowertrainState (const std::string &strName, LaePowertrainState &state)
 Get the current powertrain state. More...
 
virtual bool isStopped ()
 Test if all motors are stopped. More...
 
virtual bool isStopped (const std::string &strName)
 Test if a powertrain motor is stopped. More...
 
virtual int resetOdometers ()
 Reset all motors' odometers to the current respective encoder positions. More...
 
virtual void estop ()
 Emergency stop the robot. More...
 
virtual void resetEStop ()
 Reset emergency stop condition. More...
 
virtual int freeze ()
 Freeze (stop) all motors at the current position. More...
 
virtual int release ()
 Release motors. More...
 
virtual int stop ()
 Stop all motors at the current position. More...
 
virtual int stop (const std::vector< std::string > &vecNames)
 Stop the set of powertrain motors at the current position. More...
 
virtual int stop (const std::string &strName)
 Stop one powertrain motor at the current position. More...
 
virtual int waitForAllStop (double fSeconds)
 Wait for all motors to stop. More...
 
virtual int setGoalVelocities (const LaeMapVelocity &velocity)
 Set new or updated motor velocity goals. More...
 
virtual int setGoalDutyCycles (const LaeMapDutyCycle &duty)
 Set new or updated motor duty cycle goals. More...
 
virtual int setGoalTwist (double fVelLinear, double fVelAngular)
 Set new or updated robot twist velocity goals. More...
 
virtual void exec ()
 Execute kinematics task(s). More...
 
virtual int monitorHealth ()
 Monitor kinematics health. More...
 

Protected Member Functions

void lock ()
 Lock the shared resource. More...
 
void unlock ()
 Unlock the shared resource. More...
 
void resyncComm ()
 Attempt to resynchronize the serial communication between the host and the motor controllers.
 
virtual int configureMotorController (const LaeTunes &tunes, int nCtlr)
 Configure motor controller. More...
 
virtual int configMotorCtlrBatteryCutoffs (const LaeTunes &tunes, int nCtlr, bool &bNvmSave)
 Configure motor controller battery cutoff voltages. More...
 
virtual int configMotorCtlrLogicCutoffs (const LaeTunes &tunes, int nCtlr, bool &bNvmSave)
 Configure motor controller logic cutoff voltages. More...
 
virtual int configMotorCtlrEncoderModes (const LaeTunes &tunes, int nCtlr, bool &bNvmSave)
 Configure motor controller encoder modes. More...
 
virtual int resetMotorCtlrEncoders (int nCtlr)
 Reset all motor controller encoders to zero. More...
 
virtual int configurePtp (const LaeTunes &tunes, int nCtlr, bool &bNvSave)
 Configure powertrain pair. More...
 
virtual int configMotorVelocityPid (const LaeTunes &tunes, LaePowertrain &powertrain, bool &bNvmSave)
 Configure motor velocity PID parameters. More...
 
virtual int configMotorMaxAmpLimit (const LaeTunes &tunes, LaePowertrain &powertrain, bool &bNvmSave)
 Configure motor maximum ampere limit. More...
 
virtual int saveConfigToNvm (int nCtlr)
 Save configuration to motor controller's non-volatile memory. More...
 
virtual int sense ()
 Sense real-time state. More...
 
virtual int senseDynamics ()
 Sense real-time kinodynamics. More...
 
virtual int react ()
 React to any necessary time-critical events. More...
 
virtual int plan ()
 Plan kinematic action. More...
 
virtual int act ()
 Act on current action. More...
 
virtual void enableMotorCtlrs ()
 Enable power to motor controllers.
 
virtual void disableMotorCtlrs ()
 Disable power to motor controllers.
 

Protected Attributes

bool m_bIsEnabled
 is [not] enabled
 
bool m_bAreMotorsPowered
 motors are [not] powered
 
bool m_bIsStopped
 all motors are [not] stopped
 
int(* m_fnEnableMotorCtlrs )(void *, bool)
 enable power function
 
void * m_pEnableArg
 argument to enable function
 
motor::roboclaw::RoboClawComm m_commMotorCtlrs
 serial communication bus
 
motor::roboclaw::RoboClawm_pMotorCtlr [LaeNumMotorCtlrs]
 RoboClaw motor controllers.
 
LaePlatform m_kinPlatform
 robot platform kinematics
 
LaeMapPowertrain m_kinPowertrains
 robot powertrain kinematics
 
LaeKinActionm_pAction
 current extended kinematics action
 
pthread_mutex_t m_mutex
 mutex
 

Detailed Description

Laelaps kinematics class.

The LaeKinematics class supports control and monitoring of Laelaps powertrains and base kinodynamics.

Definition at line 119 of file laeKin.h.

Member Function Documentation

int LaeKinematics::act ( )
protectedvirtual

Act on current action.

Context:
Kinematics thread.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 1526 of file laeKin.cxx.

Referenced by unlock().

1527 {
1528  int rc;
1529 
1530  // motors are not enabled
1531  if( !m_bIsEnabled )
1532  {
1533  rc = LAE_OK;
1534  }
1535 
1536  // action requried, so execute
1537  else if( m_pAction->isExecutionRequired() )
1538  {
1539  rc = m_pAction->execute();
1540  }
1541 
1542  // nothing to do
1543  else
1544  {
1545  rc = LAE_OK;
1546  }
1547 
1548  return rc;
1549 }
LaeKinAction * m_pAction
current extended kinematics action
Definition: laeKin.h:526
virtual bool isExecutionRequired() const
Test if more action requires (more) execution.
Definition: laeKin.h:909
bool m_bIsEnabled
is [not] enabled
Definition: laeKin.h:502
virtual int execute()
Execution [sub]action.
Definition: laeKin.h:866
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
virtual bool laelaps::LaeKinematics::areMotorsPowered ( )
inlinevirtual

Test if motors are powered.

Returns
Returns true or false.

Definition at line 183 of file laeKin.h.

References configure(), m_bAreMotorsPowered, and reload().

Referenced by laelaps::LaeRobot::areMotorsPowered().

184  {
185  return m_bAreMotorsPowered;
186  }
bool m_bAreMotorsPowered
motors are [not] powered
Definition: laeKin.h:503
int LaeKinematics::close ( )
virtual

Close communication.

Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 221 of file laeKin.cxx.

Referenced by Laelaps.WatchDog.WatchDog::attach(), laelaps::LaeRobot::disconnect(), and Laelaps.WatchDog.WatchDog::open().

222 {
223  if( m_pAction != NULL )
224  {
225  m_pAction->terminate();
226  }
227 
228 #ifdef LAE_DEPRECATED
229  m_csMotorCtlrs.close(); // gpio
230 #endif // LAE_DEPRECATED
231 
232  m_commMotorCtlrs.close(); // on serial device
233 
235 
236  if( m_bIsEnabled )
237  {
238  LOGWARN("Failed to disable power to motor controllers.");
239  }
240 
241  LOGDIAG2("Closed motor controllers serial communication.");
242 
243  return LAE_OK;
244 }
LaeKinAction * m_pAction
current extended kinematics action
Definition: laeKin.h:526
motor::roboclaw::RoboClawComm m_commMotorCtlrs
serial communication bus
Definition: laeKin.h:516
bool m_bIsEnabled
is [not] enabled
Definition: laeKin.h:502
virtual void disableMotorCtlrs()
Disable power to motor controllers.
Definition: laeKin.cxx:276
virtual int terminate()
Terminate action.
Definition: laeKin.h:878
virtual int close()
Close connection to motor controller.
Definition: RoboClaw.cxx:258
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinematics::configMotorCtlrBatteryCutoffs ( const LaeTunes tunes,
int  nCtlr,
bool &  bNvmSave 
)
protectedvirtual

Configure motor controller battery cutoff voltages.

Context:
Calling thread.
Parameters
tunesLaelaps tuning parameters.
nCtlrMotor controller id.
[out]bNvmSaveDo [not] save configuration in motor contoller's non-volatile memory.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 447 of file laeKin.cxx.

Referenced by unlock().

450 {
451  string strTag = LaeDesc::prettyMotorCtlrName(nCtlr,
452  m_pMotorCtlr[nCtlr]->getAddress());
453 
454  double fMin, fMax; // working min,max values
455  double fMinMin, fMaxMax; // working min min,max max values
456  int rc; // return code
457 
458  //
459  // Read the main battery voltage cutoff settings (min, max) and set if
460  // necessary.
461  //
462 
463  LOGDIAG3("%s: Verifying main battery cutoff voltages...", strTag.c_str());
464 
465  //
466  // Read current settings.
467  //
468  rc = m_pMotorCtlr[nCtlr]->cmdReadMainBattCutoffs(fMin, fMax);
469 
470  if( rc != OK )
471  {
472  LOGWARN("%s: Failed to read main battery cutoff voltages.", strTag.c_str());
473  return LAE_OK;
474  }
475 
476  LOGDIAG3(" Current settings: [%.1lf, %.1lf]", fMin, fMax);
477 
478  // Get supported full main battery range.
479  m_pMotorCtlr[nCtlr]->getMainBattCutoffRange(fMinMin, fMaxMax);
480 
481  //
482  // Change settings. The settings are always reset to defaults on power-up,
483  // so cannot save to non-volatile memory.
484  //
485  if( (fMin != fMinMin) || (fMax != fMaxMax) )
486  {
487  rc = m_pMotorCtlr[nCtlr]->cmdSetMainBattCutoffs(fMinMin, fMaxMax);
488 
489  if( rc != OK )
490  {
491  LOGWARN("%s: Failed to set main battery cutoff voltages to "
492  "[%.1lf, %.1lf].",
493  strTag.c_str(), fMinMin, fMaxMax);
494  }
495  else
496  {
497  LOGDIAG3(" Changed settings: [%.1lf, %.1lf]", fMinMin, fMaxMax);
498  }
499  }
500 
501  //
502  // The settings are good as configured.
503  //
504  else
505  {
506  LOGDIAG3(" Good.");
507  }
508 
509  return LAE_OK;
510 }
virtual int cmdReadMainBattCutoffs(double &min, double &max)
Read the RoboClaw&#39;s main battery minimum and maximum voltage cutoff settings.
Definition: RoboClaw.cxx:694
virtual int cmdSetMainBattCutoffs(const double min, const double max)
Set the RoboClaw&#39;s main battery minimum and maximum voltage cutoff settings.
Definition: RoboClaw.cxx:721
motor::roboclaw::RoboClaw * m_pMotorCtlr[LaeNumMotorCtlrs]
RoboClaw motor controllers.
Definition: laeKin.h:518
static std::string prettyMotorCtlrName(int nCtlrId)
Create pretty motor controller identifier string.
Definition: laeDesc.cxx:596
void getMainBattCutoffRange(double &minmin, double &maxmax) const
Get the RoboClaw&#39;s main battery minimum and maximum voltage cutoff settable range.
Definition: RoboClaw.cxx:687
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinematics::configMotorCtlrEncoderModes ( const LaeTunes tunes,
int  nCtlr,
bool &  bNvmSave 
)
protectedvirtual

Configure motor controller encoder modes.

Context:
Calling thread.
Parameters
tunesLaelaps tuning parameters.
nCtlrMotor controller id.
[out]bNvmSaveDo [not] save configuration in motor contoller's non-volatile memory.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 579 of file laeKin.cxx.

Referenced by unlock().

582 {
583  string strTag = LaeDesc::prettyMotorCtlrName(nCtlr,
584  m_pMotorCtlr[nCtlr]->getAddress());
585 
586  byte_t byMode1, byMode2; // motor encoder modes
587  int rc; // return code
588 
589  //
590  // Read both motors' encoder modes and set if necessary. Laelaps uses
591  // quadrature encoding. This is a required configuration for operation.
592  //
593 
594  LOGDIAG3("%s: Verifying motor quadrature encoder modes...", strTag.c_str());
595 
596  //
597  // Read current settings.
598  //
599  rc = m_pMotorCtlr[nCtlr]->cmdReadEncoderMode(byMode1, byMode2);
600 
601  if( rc != OK )
602  {
603  LOGERROR("%s: Failed to read motor encoder modes.", strTag.c_str());
604  return -LAE_ECODE_MOT_CTLR;
605  }
606 
607  LOGDIAG3(" Current settings: [0x%02x, 0x%02x]", byMode1, byMode2);
608 
609  //
610  // Change settings. The new settings should also be saved to non-volatile
611  // memory.
612  //
613  if( (byMode1 != ParamEncModeQuad) || (byMode2 != ParamEncModeQuad) )
614  {
615  rc = m_pMotorCtlr[nCtlr]->cmdSetEncoderMode2(ParamEncModeQuad,
616  ParamEncModeQuad);
617 
618  if( rc != OK )
619  {
620  LOGERROR("%s: Failed to set motor encoders to quadrature encoding "
621  "[0x%02x, 0x%02x].",
622  strTag.c_str(), ParamEncModeQuad, ParamEncModeQuad);
623  return -LAE_ECODE_MOT_CTLR;
624  }
625 
626  LOGDIAG3(" Changed settings: [0x%02x, 0x%02x]",
627  ParamEncModeQuad, ParamEncModeQuad);
628 
629  bNvmSave = true;
630  }
631 
632  //
633  // The settings are good as configured.
634  //
635  else
636  {
637  LOGDIAG3(" Good.");
638  }
639 
640  return LAE_OK;
641 }
virtual int cmdReadEncoderMode(byte_t &mode1, byte_t &mode2)
Read encoder mode.
Definition: RoboClaw.cxx:1100
virtual int cmdSetEncoderMode2(byte_t mode1, byte_t mode2)
Set both motors&#39; encoder mode.
Definition: RoboClaw.cxx:1139
static const int LAE_ECODE_MOT_CTLR
motor controller error
Definition: laelaps.h:97
motor::roboclaw::RoboClaw * m_pMotorCtlr[LaeNumMotorCtlrs]
RoboClaw motor controllers.
Definition: laeKin.h:518
static std::string prettyMotorCtlrName(int nCtlrId)
Create pretty motor controller identifier string.
Definition: laeDesc.cxx:596
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinematics::configMotorCtlrLogicCutoffs ( const LaeTunes tunes,
int  nCtlr,
bool &  bNvmSave 
)
protectedvirtual

Configure motor controller logic cutoff voltages.

Context:
Calling thread.
Parameters
tunesLaelaps tuning parameters.
nCtlrMotor controller id.
[out]bNvmSaveDo [not] save configuration in motor contoller's non-volatile memory.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 512 of file laeKin.cxx.

Referenced by unlock().

515 {
516  string strTag = LaeDesc::prettyMotorCtlrName(nCtlr,
517  m_pMotorCtlr[nCtlr]->getAddress());
518 
519  double fMin, fMax; // working min,max values
520  double fMinMin, fMaxMax; // working min min,max max values
521  int rc; // return code
522 
523  //
524  // Read the logic 'battery' voltage cutoff settings (min, max) and set if
525  // necessary.
526  //
527  // Currently, the LB-/LB+ terminals are not connected, and the logic uses
528  // the main battery.
529  //
530 
531  LOGDIAG3("%s: Verifying logic cutoff voltages...", strTag.c_str());
532 
533  //
534  // Read current settings.
535  //
536  rc = m_pMotorCtlr[nCtlr]->cmdReadLogicCutoffs(fMin, fMax);
537 
538  if( rc != OK )
539  {
540  LOGWARN("%s: Failed to read logic cutoff voltages.", strTag.c_str());
541  return LAE_OK;
542  }
543 
544  LOGDIAG3(" Current settings: [%.1lf, %.1lf]", fMin, fMax);
545 
546  // Get supported full logic range.
547  m_pMotorCtlr[nCtlr]->getLogicCutoffRange(fMinMin, fMaxMax);
548 
549  //
550  // Change settings. The settings are always reset to defaults on power-up,
551  // so cannot save to non-volatile memory.
552  //
553  if( (fMin != fMinMin) || (fMax != fMaxMax) )
554  {
555  rc = m_pMotorCtlr[nCtlr]->cmdSetLogicCutoffs(fMinMin, fMaxMax);
556 
557  if( rc != OK )
558  {
559  LOGWARN("%s: Failed to set logic cutoff voltages to [%.1lf, %.1lf].",
560  strTag.c_str(), fMinMin, fMaxMax);
561  }
562  else
563  {
564  LOGDIAG3(" Changed settings: [%.1lf, %.1lf]", fMinMin, fMaxMax);
565  }
566  }
567 
568  //
569  // The settings are good as configured.
570  //
571  else
572  {
573  LOGDIAG3(" Good.");
574  }
575 
576  return LAE_OK;
577 }
virtual int cmdSetLogicCutoffs(const double min, const double max)
Set the RoboClaw&#39;s optional logic dedicated battery minimum and maximum voltage cutoff settings...
Definition: RoboClaw.cxx:927
motor::roboclaw::RoboClaw * m_pMotorCtlr[LaeNumMotorCtlrs]
RoboClaw motor controllers.
Definition: laeKin.h:518
void getLogicCutoffRange(double &minmin, double &maxmax) const
Get the RoboClaw&#39;s logic minimum and maximum voltage cutoff settable range.
Definition: RoboClaw.cxx:893
static std::string prettyMotorCtlrName(int nCtlrId)
Create pretty motor controller identifier string.
Definition: laeDesc.cxx:596
virtual int cmdReadLogicCutoffs(double &min, double &max)
Read the RoboClaw&#39;s optional logic dedicated battery minimum and maximum voltage cutoff settings...
Definition: RoboClaw.cxx:900
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinematics::configMotorMaxAmpLimit ( const LaeTunes tunes,
LaePowertrain powertrain,
bool &  bNvmSave 
)
protectedvirtual

Configure motor maximum ampere limit.

Context:
Calling thread.
Parameters
tunesLaelaps tuning parameters.
powertrainPowertrain kinodynmics object.
strKeyPowertrain key.
[out]bNvmSaveDo [not] save configuration in motor contoller's non-volatile memory.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 798 of file laeKin.cxx.

References LAE_VERSION, laelaps::LaePowertrain::m_attr, laelaps::LaePowertrainAttr::m_nMotorCtlrId, laelaps::LaePowertrainAttr::m_nMotorId, laelaps::LaePowertrainAttr::m_nMotorIndex, and laelaps::LaePowertrain::m_strName.

Referenced by unlock().

801 {
802  string strKey = powertrain.m_strName;
803  int nCtlrId = powertrain.m_attr.m_nMotorCtlrId;
804  int nMotorId = powertrain.m_attr.m_nMotorId;
805  int nMotor = powertrain.m_attr.m_nMotorIndex;
806  byte_t addr = m_pMotorCtlr[nCtlrId]->getAddress();
807  string strTag = LaeDesc::prettyMotorName(nCtlrId, addr, nMotorId);
808 
809  double fCurMaxAmps, fMaxAmps; // max. amp limits
810  int rc; // return code
811 
812  //
813  // Read motor's maximum current limit, and set if necessary.
814  //
815  // Note: Not limiting the amps can cause motor burn out.
816  //
817 
818  LOGDIAG3("%s: Verifying maximum amp limit parameter...", strTag.c_str());
819 
820  //
821  // Read current settings.
822  //
823  rc = m_pMotorCtlr[nCtlrId]->cmdReadMotorMaxCurrentLimit(nMotor, fCurMaxAmps);
824 
825  if( rc != OK )
826  {
827  LOGERROR("%s: Failed to read maximum current limit.", strTag.c_str());
828  return -LAE_ECODE_MOT_CTLR;
829  }
830 
831  LOGDIAG3(" Current settings: %.2lf amps.", fCurMaxAmps);
832 
833  if( RtDb.m_product.m_uProdHwVer == LAE_VERSION(2, 0, 0) )
834  {
835  fMaxAmps = LaeMotorMaxAmps_2_0 - 0.05;
836  }
837  else
838  {
839  fMaxAmps = LaeMotorMaxAmps_2_1 - 0.05;
840  }
841 
842  //
843  // Change settings. The new settings should also be saved to non-volatile
844  // memory.
845  //
846  if( fCurMaxAmps != fMaxAmps )
847  {
848  rc = m_pMotorCtlr[nCtlrId]->cmdSetMotorMaxCurrentLimit(nMotor, fMaxAmps);
849 
850  if( rc != OK)
851  {
852  LOGERROR("%s: Failed to set maximum current limit to %.2lf.",
853  strTag.c_str(), fMaxAmps);
854  return -LAE_ECODE_MOT_CTLR;
855  }
856  else
857  {
858  LOGDIAG3(" Changed settings: %.2lf amps.", fMaxAmps);
859  bNvmSave = true;
860  }
861  }
862 
863  //
864  // The settings are good as configured.
865  //
866  else
867  {
868  LOGDIAG3(" Good.");
869  }
870 
871  return LAE_OK;
872 }
int m_nMotorCtlrId
motor controller id
Definition: laePowertrain.h:81
virtual int cmdSetMotorMaxCurrentLimit(int motor, const double maxAmps)
Set a motor&#39;s maximum current limit.
Definition: RoboClaw.cxx:832
LaeDbProduct m_product
product data
Definition: laeDb.h:227
static std::string prettyMotorName(int nMotorId)
Create pretty motor/powertrain identifier string.
Definition: laeDesc.cxx:626
uint_t m_uProdHwVer
product hardware version number
Definition: laeDb.h:80
static const double LaeMotorMaxAmps_2_0
max amp limit/motor
Definition: laeMotor.h:171
std::string m_strName
powertrain unique name (key)
virtual int cmdReadMotorMaxCurrentLimit(int motor, double &maxAmps)
Read a motor&#39;s maximum current limit.
Definition: RoboClaw.cxx:793
int m_nMotorIndex
motor controller unique motor index
Definition: laePowertrain.h:82
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
static const int LAE_ECODE_MOT_CTLR
motor controller error
Definition: laelaps.h:97
LaePowertrainAttr m_attr
semi-fixed attribute data
motor::roboclaw::RoboClaw * m_pMotorCtlr[LaeNumMotorCtlrs]
RoboClaw motor controllers.
Definition: laeKin.h:518
byte_t getAddress() const
Get the controller address associated with this class instance.
Definition: RoboClaw.h:872
#define LAE_VERSION(major, minor, revision)
Convert version triplet to integer equivalent.
Definition: laelaps.h:158
static const double LaeMotorMaxAmps_2_1
max amp limit/motor
Definition: laeMotor.h:172
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinematics::configMotorVelocityPid ( const LaeTunes tunes,
LaePowertrain powertrain,
bool &  bNvmSave 
)
protectedvirtual

Configure motor velocity PID parameters.

Context:
Calling thread.
Parameters
tunesLaelaps tuning parameters.
powertrainPowertrain kinodynmics object.
[out]bNvmSaveDo [not] save configuration in motor contoller's non-volatile memory.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 711 of file laeKin.cxx.

References laelaps::LaeTunes::getVelPidKParams(), laelaps::LaePowertrain::m_attr, laelaps::LaePowertrainAttr::m_nMotorCtlrId, laelaps::LaePowertrainAttr::m_nMotorId, laelaps::LaePowertrainAttr::m_nMotorIndex, laelaps::LaePowertrain::m_strName, and laelaps::LaePowertrainAttr::m_uMaxQpps.

Referenced by unlock().

714 {
715  string strKey = powertrain.m_strName;
716  int nCtlrId = powertrain.m_attr.m_nMotorCtlrId;
717  int nMotorId = powertrain.m_attr.m_nMotorId;
718  int nMotor = powertrain.m_attr.m_nMotorIndex;
719  byte_t addr = m_pMotorCtlr[nCtlrId]->getAddress();
720  string strTag = LaeDesc::prettyMotorName(nCtlrId, addr, nMotorId);
721 
722  u32_t uKp, uKi, uKd, uQpps; // existing PID settings.
723  double fTuneKp, fTuneKi, fTuneKd; // tune PID parameters
724  u32_t uTuneKp, uTuneKi, uTuneKd, uTuneQpps; // converted tune target PID
725  int rc; // return code
726 
727  //
728  // Read motor's velocity PID parameters, and set if necessary.
729  //
730 
731  LOGDIAG3("%s: Verifying velocity PID parameters...", strTag.c_str());
732 
733  //
734  // Read current settings.
735  //
736  rc = m_pMotorCtlr[nCtlrId]->cmdReadVelocityPidConst(nMotor,
737  uKp, uKi, uKd, uQpps);
738 
739  if( rc != OK )
740  {
741  LOGWARN("%s: Failed to read velocity PID constants.", strTag.c_str());
742  return LAE_OK;
743  }
744 
745  fTuneKp = (double)uKp / (double)ParamVelPidCvt;
746  fTuneKi = (double)uKi / (double)ParamVelPidCvt;
747  fTuneKd = (double)uKd / (double)ParamVelPidCvt;
748 
749  LOGDIAG3(" Current settings: "
750  "Kp=%lf (raw=0x%08x), Ki=%lf (raw=0x%08x), Kd=%lf (raw=0x%08x), Qpps=%u.",
751  fTuneKp, uKp, fTuneKi, uKi, fTuneKd, uKd, uQpps);
752 
753  // Get the tune parameters in "natural" floating-point representation
754  tunes.getVelPidKParams(strKey, fTuneKp, fTuneKi, fTuneKd);
755 
756  // Convert to motor controller speak.
757  uTuneKp = (u32_t)(fTuneKp * (double)ParamVelPidCvt);
758  uTuneKi = (u32_t)(fTuneKi * (double)ParamVelPidCvt);
759  uTuneKd = (u32_t)(fTuneKd * (double)ParamVelPidCvt);
760  uTuneQpps = (u32_t)(powertrain.m_attr.m_uMaxQpps);
761 
762  //
763  // Change settings. The new settings should also be saved to non-volatile
764  // memory.
765  //
766  if( (uKp != uTuneKp) || (uKi != uTuneKi) || (uKd != uTuneKd) ||
767  (uQpps != uTuneQpps) )
768  {
769  rc = m_pMotorCtlr[nCtlrId]->cmdSetVelocityPidConst(nMotor,
770  uTuneKp, uTuneKi, uTuneKd, uTuneQpps);
771 
772  if( rc != OK)
773  {
774  LOGWARN("%s: Failed to set velocity PID constants.", strTag.c_str());
775  }
776  else
777  {
778  LOGDIAG3(" Changed settings: "
779  "Kp=%lf (raw=0x%08x), Ki=%lf (raw=0x%08x), Kd=%lf (raw=0x%08x), "
780  "Qpps=%u.",
781  fTuneKp, uTuneKp, fTuneKi, uTuneKi, fTuneKd, uTuneKd, uTuneQpps);
782 
783  bNvmSave = true;
784  }
785  }
786 
787  //
788  // The settings are good as configured.
789  //
790  else
791  {
792  LOGDIAG3(" Good.");
793  }
794 
795  return LAE_OK;
796 }
int m_nMotorCtlrId
motor controller id
Definition: laePowertrain.h:81
static std::string prettyMotorName(int nMotorId)
Create pretty motor/powertrain identifier string.
Definition: laeDesc.cxx:626
void getVelPidKParams(const std::string &strName, double &fKp, double &fKi, double &fKd) const
Get motor velocity PID K tune parameters.
Definition: laeTune.cxx:356
std::string m_strName
powertrain unique name (key)
int m_nMotorIndex
motor controller unique motor index
Definition: laePowertrain.h:82
LaePowertrainAttr m_attr
semi-fixed attribute data
virtual int cmdSetVelocityPidConst(int motor, const u32_t Kp, const u32_t Ki, const u32_t Kd, const u32_t qpps)
Set motor&#39;s velocity PID constants.
Definition: RoboClaw.cxx:997
uint_t m_uMaxQpps
maximum quadrature pulses/second rps
Definition: laePowertrain.h:90
motor::roboclaw::RoboClaw * m_pMotorCtlr[LaeNumMotorCtlrs]
RoboClaw motor controllers.
Definition: laeKin.h:518
byte_t getAddress() const
Get the controller address associated with this class instance.
Definition: RoboClaw.h:872
virtual int cmdReadVelocityPidConst(int motor, u32_t &Kp, u32_t &Ki, u32_t &Kd, u32_t &qpps)
Read motor&#39;s velocity PID constants.
Definition: RoboClaw.cxx:958
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinematics::configure ( const LaeDesc desc)
virtual

Configure kinematics chains and data from product description.

Parameters
descProduct description.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 331 of file laeKin.cxx.

References laelaps::LaePowertrain::configure(), laelaps::LaeDesc::m_mapDescPowertrain, laelaps::LaeDesc::m_pDescBase, and laelaps::LaePowertrain::m_strName.

Referenced by areMotorsPowered(), and laelaps::LaeRobot::configForOperation().

332 {
333  LaeDesc::MapDescPowertrain::const_iterator iter;
334  LaePowertrain train;
335  int rc = LAE_OK;
336 
337  //
338  // Powertrains
339  //
340  for(iter = desc.m_mapDescPowertrain.begin();
341  iter != desc.m_mapDescPowertrain.end();
342  ++iter)
343  {
344  // configure powertrain kinematics
345  train.configure(*iter->second);
346 
347  //
348  // Sanity checks.
349  //
350 
351  //
352  // Add to kinematic chain.
353  //
354  m_kinPowertrains[train.m_strName] = train;
355  }
356 
357  //
358  // Robot platform
359  //
361 
362  LOGDIAG2("Configured motor controllers from robot description.");
363 
364  return rc;
365 }
LaeDescBase * m_pDescBase
base description
Definition: laeDesc.h:523
virtual int configure(const LaeDescBase &desc)
Configure robot platform from product description.
std::string m_strName
powertrain unique name (key)
LaePlatform m_kinPlatform
robot platform kinematics
Definition: laeKin.h:522
virtual int configure(const LaeDescPowertrain &desc)
Configure powertrain from product description.
LaeMapPowertrain m_kinPowertrains
robot powertrain kinematics
Definition: laeKin.h:523
MapDescPowertrain m_mapDescPowertrain
powertrain descriptions
Definition: laeDesc.h:525
Powertrain data class.
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinematics::configure ( const LaeTunes tunes)
virtual

Configure kinematics for operation.

Context:
Calling thread.
Parameters
tunesLaelaps tuning parameters.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 367 of file laeKin.cxx.

368 {
369  int nCtlr; // motor controller id
370  int rc; // return code
371 
372  for(nCtlr = 0; nCtlr < LaeNumMotorCtlrs; ++nCtlr)
373  {
374  if( (rc = configureMotorController(tunes, nCtlr)) != LAE_OK )
375  {
376  break;
377  }
378  }
379 
380  m_kinPlatform.configure(tunes);
381 
382  if( rc == LAE_OK )
383  {
384  LOGDIAG2("Tuned motor controllers.");
385  }
386 
387  return rc;
388 }
virtual int configure(const LaeDescBase &desc)
Configure robot platform from product description.
LaePlatform m_kinPlatform
robot platform kinematics
Definition: laeKin.h:522
static const int LaeNumMotorCtlrs
number of motor controllers
Definition: laeMotor.h:115
virtual int configureMotorController(const LaeTunes &tunes, int nCtlr)
Configure motor controller.
Definition: laeKin.cxx:390
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinematics::configureMotorController ( const LaeTunes tunes,
int  nCtlr 
)
protectedvirtual

Configure motor controller.

Context:
Calling thread.
Parameters
tunesLaelaps tuning parameters.
nCtlrMotor controller id.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 390 of file laeKin.cxx.

Referenced by unlock().

391 {
392  bool bNvmSave; // do [not] save changes to ctlr's eeprom
393  int rc; // return code
394 
395  bNvmSave = false;
396 
397  //
398  // Make sure motor controllers are configured correctly.
399  //
400  // All operations are read, conditional writes.
401  // Both controllers have identical config.
402  //
403 
404  // battery cutoffs
405  if( (rc = configMotorCtlrBatteryCutoffs(tunes, nCtlr, bNvmSave)) != LAE_OK )
406  {
407  return rc;
408  }
409 
410  // logic cutoffs
411  if( (rc = configMotorCtlrLogicCutoffs(tunes, nCtlr, bNvmSave)) != LAE_OK )
412  {
413  return rc;
414  }
415 
416  // encoder modes
417  if( (rc = configMotorCtlrEncoderModes(tunes, nCtlr, bNvmSave)) != LAE_OK )
418  {
419  return rc;
420  }
421 
422  //
423  // Configure the motor controller's powertrain pair.
424  //
425  if( (rc = configurePtp(tunes, nCtlr, bNvmSave)) != LAE_OK )
426  {
427  return rc;
428  }
429 
430  //
431  // If any settings, that can be saved, have changed, then save to
432  // non-volatile EEPROM.
433  //
434  if( bNvmSave )
435  {
436  saveConfigToNvm(nCtlr);
437  }
438 
439  //
440  // Set controller state values.
441  //
442  resetMotorCtlrEncoders(nCtlr);
443 
444  return LAE_OK;
445 }
virtual int configMotorCtlrEncoderModes(const LaeTunes &tunes, int nCtlr, bool &bNvmSave)
Configure motor controller encoder modes.
Definition: laeKin.cxx:579
virtual int configurePtp(const LaeTunes &tunes, int nCtlr, bool &bNvSave)
Configure powertrain pair.
Definition: laeKin.cxx:664
virtual int resetMotorCtlrEncoders(int nCtlr)
Reset all motor controller encoders to zero.
Definition: laeKin.cxx:643
virtual int configMotorCtlrBatteryCutoffs(const LaeTunes &tunes, int nCtlr, bool &bNvmSave)
Configure motor controller battery cutoff voltages.
Definition: laeKin.cxx:447
virtual int configMotorCtlrLogicCutoffs(const LaeTunes &tunes, int nCtlr, bool &bNvmSave)
Configure motor controller logic cutoff voltages.
Definition: laeKin.cxx:512
virtual int saveConfigToNvm(int nCtlr)
Save configuration to motor controller&#39;s non-volatile memory.
Definition: laeKin.cxx:874
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinematics::configurePtp ( const LaeTunes tunes,
int  nCtlr,
bool &  bNvSave 
)
protectedvirtual

Configure powertrain pair.

Context:
Calling thread.
Parameters
tunesLaelaps tuning parameters.
nCtlrMotor controller id.
[out]bNvmSaveDo [not] save configuration in motor contoller's non-volatile memory.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 664 of file laeKin.cxx.

Referenced by unlock().

667 {
668  LaeMapPowertrain::iterator pos;
669 
670  int nMotor; // motor index
671  int rc; // return code
672 
673  string strKey = m_pMotorCtlr[nCtlr]->getNameId();
674 
675  for(nMotor = LaeMotorLeft; nMotor < LaeNumMotorsPerCtlr; ++nMotor)
676  {
677  strKey = LaePowertrain::toKey(nCtlr, nMotor);
678 
679  // - - - -
680  // Update powertrain attributes with tuning parameters values.
681  // - - - -
682  if( (pos = m_kinPowertrains.find(strKey)) == m_kinPowertrains.end() )
683  {
684  LOGWARN("Cannot find powertrain %s - ignoring.", strKey.c_str());
685  continue;
686  }
687 
688  // configure parameters for powertrain kinodynamics
689  pos->second.configure(tunes);
690 
691  // velocity PID
692  if( (rc = configMotorVelocityPid(tunes, pos->second, bNvmSave)) != LAE_OK )
693  {
694  return rc;
695  }
696 
697  // maximum ampere limit
698  if( (rc = configMotorMaxAmpLimit(tunes, pos->second, bNvmSave)) != LAE_OK )
699  {
700  return rc;
701  }
702 
703  //
704  // RDK TODO 63,64 Read motor position PID
705  // RDK TODO 61,62 Set motor position PID
706  }
707 
708  return LAE_OK;
709 }
virtual int configMotorVelocityPid(const LaeTunes &tunes, LaePowertrain &powertrain, bool &bNvmSave)
Configure motor velocity PID parameters.
Definition: laeKin.cxx:711
static const int LaeMotorLeft
left motors
Definition: laeMotor.h:128
LaeMapPowertrain m_kinPowertrains
robot powertrain kinematics
Definition: laeKin.h:523
std::string getNameId() const
Get class instance name identifier.
Definition: RoboClaw.h:895
static std::string toKey(const int nCtlrId, const int nMotorIndex)
Map motor controller id and motor index to powertrain name (key).
motor::roboclaw::RoboClaw * m_pMotorCtlr[LaeNumMotorCtlrs]
RoboClaw motor controllers.
Definition: laeKin.h:518
virtual int configMotorMaxAmpLimit(const LaeTunes &tunes, LaePowertrain &powertrain, bool &bNvmSave)
Configure motor maximum ampere limit.
Definition: laeKin.cxx:798
static const int LaeNumMotorsPerCtlr
number of motors/controller
Definition: laeMotor.h:130
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
void LaeKinematics::estop ( )
virtual

Emergency stop the robot.

All motors will stop and power to motor controllers disabled.

Context:
Calling thread.

Definition at line 1064 of file laeKin.cxx.

Referenced by laelaps::LaeRobot::estop(), and getPowertrainMap().

1065 {
1066  int nCtlr; // motor controller id
1067 
1068  lock();
1069 
1070  if( m_bIsEnabled )
1071  {
1072  m_pAction->terminate();
1073 
1074  for(nCtlr = 0; nCtlr < LaeNumMotorCtlrs; ++nCtlr)
1075  {
1076  m_pMotorCtlr[nCtlr]->cmdEStop();
1077  }
1078 
1080  }
1081 
1082  unlock();
1083 }
LaeKinAction * m_pAction
current extended kinematics action
Definition: laeKin.h:526
bool m_bIsEnabled
is [not] enabled
Definition: laeKin.h:502
motor::roboclaw::RoboClaw * m_pMotorCtlr[LaeNumMotorCtlrs]
RoboClaw motor controllers.
Definition: laeKin.h:518
virtual void disableMotorCtlrs()
Disable power to motor controllers.
Definition: laeKin.cxx:276
void unlock()
Unlock the shared resource.
Definition: laeKin.h:550
void lock()
Lock the shared resource.
Definition: laeKin.h:539
static const int LaeNumMotorCtlrs
number of motor controllers
Definition: laeMotor.h:115
virtual int terminate()
Terminate action.
Definition: laeKin.h:878
virtual int cmdEStop()
Emergency stop all motors.
Definition: RoboClaw.cxx:1729
void LaeKinematics::exec ( )
virtual

Execute kinematics task(s).

Context:
Kinematic thread.

Definition at line 1600 of file laeKin.cxx.

Referenced by laelaps::LaeThreadKin::exec(), and freeze().

1601 {
1602  lock();
1603 
1604  //
1605  // Auto-Repair
1606  //
1607  // The motor controllers should be enabled, but the watchdog thread has
1608  // detected that they are not. This should not happen, so re-enable.
1609  //
1611  {
1612  LOGERROR("Motor controllers have been unexpectedly disaabled. Re-enable.");
1613  unlock();
1614  resyncComm();
1615  lock();
1616  }
1617 
1618  // sense environment and dynamic state
1619  sense();
1620 
1621  // react to immediate stimulii
1622  react();
1623 
1624  // plan motions
1625  plan();
1626 
1627  // act on planned motions
1628  act();
1629 
1630  unlock();
1631 }
virtual int plan()
Plan kinematic action.
Definition: laeKin.cxx:1501
void resyncComm()
Attempt to resynchronize the serial communication between the host and the motor controllers.
Definition: laeKin.cxx:313
virtual int react()
React to any necessary time-critical events.
Definition: laeKin.cxx:1496
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
virtual int act()
Act on current action.
Definition: laeKin.cxx:1526
LaeDbEnable m_enable
key gpio state data
Definition: laeDb.h:230
bool m_bIsEnabled
is [not] enabled
Definition: laeKin.h:502
bool m_bMotorCtlr
motor controller [not] enabled
Definition: laeDb.h:121
virtual int sense()
Sense real-time state.
Definition: laeKin.cxx:1423
void unlock()
Unlock the shared resource.
Definition: laeKin.h:550
void lock()
Lock the shared resource.
Definition: laeKin.h:539
virtual int laelaps::LaeKinematics::freeze ( )
inlinevirtual

Freeze (stop) all motors at the current position.

Synomonous with stop().

Context:
Calling thread.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 355 of file laeKin.h.

References exec(), monitorHealth(), release(), setGoalDutyCycles(), setGoalTwist(), setGoalVelocities(), stop(), and waitForAllStop().

356  {
357  return stop();
358  }
virtual int stop()
Stop all motors at the current position.
Definition: laeKin.cxx:1125
RoboClaw * LaeKinematics::getMotorCtlr ( const int  nMotorCtlrId)

Get pointer to motor controller by name (key).

Parameters
nMotorCtlrIdMotor controller unique identifier.
Returns
On success, the pointer to motor controller object is returned.
On failure, NULL is returned.

Definition at line 918 of file laeKin.cxx.

Referenced by laelaps::LaeKinActionVelocity::execute(), laelaps::LaeKinActionDutyCycle::execute(), laelaps::LaeKinActionTwist::execute(), getPlatform(), laelaps::LaeKinActionVelocity::terminate(), laelaps::LaeKinActionDutyCycle::terminate(), and laelaps::LaeKinActionTwist::terminate().

919 {
920  if( (nMotorCtlrId >= 0) && (nMotorCtlrId < LaeNumMotorCtlrs) )
921  {
922  return m_pMotorCtlr[nMotorCtlrId];
923  }
924  else
925  {
926  return NULL;
927  }
928 }
motor::roboclaw::RoboClaw * m_pMotorCtlr[LaeNumMotorCtlrs]
RoboClaw motor controllers.
Definition: laeKin.h:518
static const int LaeNumMotorCtlrs
number of motor controllers
Definition: laeMotor.h:115
LaePlatform& laelaps::LaeKinematics::getPlatform ( )
inline

Get robot platform kinodynamics.

Returns
Returns reference to robot platform kinodynamics object.

Definition at line 226 of file laeKin.h.

References getMotorCtlr(), and m_kinPlatform.

Referenced by laelaps::LaeRptRobotStatus::generate(), and laelaps::LaeKinActionTwist::plan().

227  {
228  return m_kinPlatform;
229  }
LaePlatform m_kinPlatform
robot platform kinematics
Definition: laeKin.h:522
LaePowertrain* laelaps::LaeKinematics::getPowertrain ( const std::string &  strName)

Get pointer to powertrain by name (key).

Parameters
strNamePowertrain name (key).
Returns
On success, the pointer to powertrain kinodynamics object is returned.
On failure, NULL is returned.

Referenced by laelaps::LaeKinActionDutyCycle::execute(), laelaps::LaeRobot::getNavigationState(), laelaps::LaeRobot::getPowertrain(), getPowertrainMap(), laelaps::LaeKinActionVelocity::plan(), and laelaps::LaeKinActionTwist::plan().

LaePowertrain * LaeKinematics::getPowertrain ( int  nCtlr,
int  nMotor 
)

Get pointer to powertrain by controller id and motor index.

Parameters
nCtlrMotor controller id.
nMotorMotor index within motor controller.
Returns
On success, the pointer to powertrain kinodynamics object is returned.
On failure, NULL is returned.

Definition at line 942 of file laeKin.cxx.

943 {
944  std::string strName = LaePowertrain::toKey(nCtlr, nMotor);
945 
946  if( m_kinPowertrains.find(strName) != m_kinPowertrains.end() )
947  {
948  return &m_kinPowertrains[strName];
949  }
950  else
951  {
952  return NULL;
953  }
954 }
LaeMapPowertrain m_kinPowertrains
robot powertrain kinematics
Definition: laeKin.h:523
static std::string toKey(const int nCtlrId, const int nMotorIndex)
Map motor controller id and motor index to powertrain name (key).
LaePowertrain * LaeKinematics::getPowertrain ( int  nMotorId)

Get pointer to powertrain by motor id.

Parameters
nMotorIdMotor id.
Returns
On success, the pointer to powertrain kinodynamics object is returned.
On failure, NULL is returned.

Definition at line 956 of file laeKin.cxx.

957 {
958  std::string strName = LaePowertrain::toKey(nMotorId);
959 
960  if( m_kinPowertrains.find(strName) != m_kinPowertrains.end() )
961  {
962  return &m_kinPowertrains[strName];
963  }
964  else
965  {
966  return NULL;
967  }
968 }
LaeMapPowertrain m_kinPowertrains
robot powertrain kinematics
Definition: laeKin.h:523
static std::string toKey(const int nCtlrId, const int nMotorIndex)
Map motor controller id and motor index to powertrain name (key).
LaeMapPowertrain& laelaps::LaeKinematics::getPowertrainMap ( )
inline

Get map of all powertrain kinodynamics.

Returns
Returns reference to map of powertrain kinodynamics objects.

Definition at line 247 of file laeKin.h.

References estop(), getPowertrain(), getPowertrainState(), isStopped(), m_kinPowertrains, resetEStop(), and resetOdometers().

Referenced by laelaps::LaeRptRobotStatus::generate().

248  {
249  return m_kinPowertrains;
250  }
LaeMapPowertrain m_kinPowertrains
robot powertrain kinematics
Definition: laeKin.h:523
int LaeKinematics::getPowertrainState ( const std::string &  strName,
LaePowertrainState state 
)
virtual

Get the current powertrain state.

Context:
Calling thread.
Parameters
[in]strNamePowertrain unique name.
[out]stateCurrent powertrain state.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 970 of file laeKin.cxx.

Referenced by getPowertrainMap().

972 {
973  LaeMapPowertrain::iterator pos;
974 
975  if( (pos = m_kinPowertrains.find(strName)) != m_kinPowertrains.end() )
976  {
977  jointState = pos->second.m_state;
978  return LAE_OK;
979  }
980  else
981  {
982  return -LAE_ECODE_BAD_VAL;
983  }
984 }
LaeMapPowertrain m_kinPowertrains
robot powertrain kinematics
Definition: laeKin.h:523
static const int LAE_ECODE_BAD_VAL
bad value general error
Definition: laelaps.h:76
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
virtual bool laelaps::LaeKinematics::isEnabled ( )
inlinevirtual

Test if motors are enabled.

Returns
Returns true or false.

Definition at line 173 of file laeKin.h.

References m_bIsEnabled.

Referenced by laelaps::LaeRobot::estop(), and laelaps::LaeRobot::resetEStop().

174  {
175  return m_bIsEnabled;
176  }
bool m_bIsEnabled
is [not] enabled
Definition: laeKin.h:502
bool LaeKinematics::isStopped ( )
virtual

Test if all motors are stopped.

Returns
Returns true if all are stopped, false otherwise.

Definition at line 986 of file laeKin.cxx.

References iabs().

Referenced by getPowertrainMap(), and laelaps::LaeRobot::isInMotion().

987 {
988  bool bIsStopped; // all motors are [not] stopped
989  LaeMapPowertrain::iterator iter; // kinematics chain iterator
990 
991  for(iter = m_kinPowertrains.begin(), bIsStopped = true;
992  (iter != m_kinPowertrains.end()) && bIsStopped;
993  ++iter)
994  {
995  if( iabs(iter->second.m_state.m_nSpeed) > SpeedReallyZero )
996  {
997  bIsStopped = false;
998  }
999  }
1000 
1001  m_bIsStopped = bIsStopped;
1002  RtDb.m_robotstatus.m_bInMotion = m_bIsStopped? false: true;
1003 
1004  return m_bIsStopped;
1005 }
LaeDbRobotStatus m_robotstatus
robot status data
Definition: laeDb.h:229
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
LaeMapPowertrain m_kinPowertrains
robot powertrain kinematics
Definition: laeKin.h:523
int iabs(int a)
Integer absolute value.
Definition: laeUtils.h:148
bool m_bInMotion
1+ motors are [not] moving
Definition: laeDb.h:112
bool m_bIsStopped
all motors are [not] stopped
Definition: laeKin.h:504
bool LaeKinematics::isStopped ( const std::string &  strName)
virtual

Test if a powertrain motor is stopped.

Parameters
strNamePowertrain unique name.
Returns
Returns true if stopped, false otherwise.

Definition at line 1007 of file laeKin.cxx.

References iabs().

1008 {
1009  LaeMapPowertrain::iterator pos;
1010 
1011  if( (pos = m_kinPowertrains.find(strName)) != m_kinPowertrains.end() )
1012  {
1013  return iabs(pos->second.m_state.m_nSpeed) <= SpeedReallyZero;
1014  }
1015  else // non-existent joints don't move
1016  {
1017  return true;
1018  }
1019 }
LaeMapPowertrain m_kinPowertrains
robot powertrain kinematics
Definition: laeKin.h:523
int iabs(int a)
Integer absolute value.
Definition: laeUtils.h:148
void laelaps::LaeKinematics::lock ( )
inlineprotected

Lock the shared resource.

The lock()/unlock() primitives provide a safe multi-threading.

Context:
Any.

Definition at line 539 of file laeKin.h.

540  {
541  pthread_mutex_lock(&m_mutex);
542  }
pthread_mutex_t m_mutex
mutex
Definition: laeKin.h:529
int LaeKinematics::monitorHealth ( )
virtual

Monitor kinematics health.

Context:
Kinematics thread.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 1551 of file laeKin.cxx.

References laelaps::LaePowertrain::updateHealth().

Referenced by laelaps::LaeThreadKin::exec(), and freeze().

1552 {
1553  int nCtlr; // motor controller id
1554  int nMotor; // motor index
1555  double volts; // main battery voltage
1556  double temp; // board temperature
1557  uint_t status; // board status
1558  LaePowertrain *pTrain; // pointer to joint
1559 
1560  if( !m_bIsEnabled )
1561  {
1562  return LAE_OK;
1563  }
1564 
1565  lock();
1566 
1567  //
1568  // Read health data.
1569  //
1570  for(nCtlr = 0; nCtlr < LaeNumMotorCtlrs; ++nCtlr)
1571  {
1572  m_pMotorCtlr[nCtlr]->cmdReadMainBattVoltage(volts);
1573  m_pMotorCtlr[nCtlr]->cmdReadBoardTemperature(temp);
1574  m_pMotorCtlr[nCtlr]->cmdReadStatus(status);
1575 
1576  RtDb.m_motorctlr[nCtlr].m_uStatus = status;
1577  RtDb.m_motorctlr[nCtlr].m_fTemperature = temp;
1578  RtDb.m_motorctlr[nCtlr].m_fBatteryVoltage = volts;
1579 
1580  for(nMotor = 0; nMotor < LaeNumMotorsPerCtlr; ++nMotor)
1581  {
1582  if( (pTrain = getPowertrain(nCtlr, nMotor)) != NULL )
1583  {
1584  pTrain->updateHealth(volts, temp, status);
1585  }
1586  }
1587 
1588  m_kinPlatform.updateCtlrHealth(nCtlr, volts, temp, status);
1589  }
1590 
1592 
1593  LOGDIAG4("Kinematics Thread: Monitored health of motor controllers.");
1594 
1595  unlock();
1596 
1597  return LAE_OK;
1598 }
LaePowertrain * getPowertrain(const std::string &strName)
Get pointer to powertrain by name (key).
double m_fBatteryVoltage
sensed battery voltage (V)
Definition: laeDb.h:136
LaePlatform m_kinPlatform
robot platform kinematics
Definition: laeKin.h:522
virtual int updateHealth(double fVolts, double fTemp, uint_t uCtlrStatus)
Update motor health state.
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
LaeMapPowertrain m_kinPowertrains
robot powertrain kinematics
Definition: laeKin.h:523
virtual int cmdReadBoardTemperature(double &temp)
Read RoboClaw board&#39;s temperature.
Definition: RoboClaw.cxx:1034
virtual int updateHealth(const LaeMapPowertrain &mapPowertrains)
Update robot platform health state.
bool m_bIsEnabled
is [not] enabled
Definition: laeKin.h:502
LaeDbMotorCtlr m_motorctlr[LaeNumMotorCtlrs]
motor controller and motor data
Definition: laeDb.h:231
double m_fTemperature
sensed temperature (C)
Definition: laeDb.h:135
u32_t m_uStatus
status bits
Definition: laeDb.h:134
motor::roboclaw::RoboClaw * m_pMotorCtlr[LaeNumMotorCtlrs]
RoboClaw motor controllers.
Definition: laeKin.h:518
virtual int cmdReadStatus(uint_t &status)
Read RoboClaw board&#39;s status bits.
Definition: RoboClaw.cxx:1055
virtual int updateCtlrHealth(int nCtlr, double fVolts, double fTemp, uint_t uStatus)
Update robot platform motor controller health state.
void unlock()
Unlock the shared resource.
Definition: laeKin.h:550
void lock()
Lock the shared resource.
Definition: laeKin.h:539
static const int LaeNumMotorCtlrs
number of motor controllers
Definition: laeMotor.h:115
virtual int cmdReadMainBattVoltage(double &volts)
Read the RoboClaw&#39;s main battery input voltage.
Definition: RoboClaw.cxx:667
Powertrain data class.
static const int LaeNumMotorsPerCtlr
number of motors/controller
Definition: laeMotor.h:130
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinematics::open ( const std::string &  strDevMotorCtlrs,
const int  nBaudRate,
int(*)(void *, bool)  fnEnable = NULL,
void *  pEnableArg = NULL 
)

Open communication with the Laelaps motor controllers.

Motors controller serial interface support multi-drop, so one serial device can support up to 8 motor controllers. A GPIO pin selects the motor controller.

Parameters
strDevMotorCtlrsMotor controllers serial device name.
nBaudRateMotor controllers serial baudrate.
fnEnableMotor controllers enable power function.
pEnableArgEnable power function argument.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 141 of file laeKin.cxx.

References laelaps::getRealDeviceName().

Referenced by laelaps::LaeRobot::connMotorControllers().

145 {
146  string strDevName; // real device names
147  int nCtlr; // motor controller id
148 
149  m_fnEnableMotorCtlrs = fnEnable;
150  m_pEnableArg = pEnableArg;
151  m_bIsEnabled = false;
152 
153  // Enable power to motor controllers
155 
156  if( !m_bIsEnabled )
157  {
158  LOGERROR("Failed to enable power to motor controllers.");
159  return -LAE_ECODE_IO;
160  }
161 
162 #ifdef LAE_DEPRECATED
163  // Open the motor controller chip select via gpio
164  if( m_csMotorCtlrs.open(LaeGpioMotorCtlrCs) < 0 )
165  {
166  LOGSYSERROR("Failed to open motor controller chip select on GPIO pin %d.",
168  return -LAE_ECODE_MOT_CTLR;
169  }
170 
171  LOGDIAG2("Opened motor controllers chip select signal on GPIO %d.",
173 #endif // LAE_DEPRECATED
174 
175  // Get the real device name, not any symbolic links.
176  strDevName = getRealDeviceName(strDevMotorCtlrs);
177 
178  // Open the motor controller.
179  if( m_commMotorCtlrs.open(strDevName, nBaudRate) < 0 )
180  {
181  LOGERROR("%s: Failed to open motor controller port at %d baud.",
182  strDevName.c_str(), nBaudRate);
183  return -LAE_ECODE_MOT_CTLR;
184  }
185 
186  LOGDIAG3("Open motor controllers serial communication on %s@%d.",
187  strDevName.c_str(), nBaudRate);
188 
189  //
190  // Create front motor controller interface.
191  //
192  nCtlr = LaeMotorCtlrIdFront;
193  m_pMotorCtlr[nCtlr] =
197 
198  //
199  // Create rear motor controller interface.
200  //
201  nCtlr = LaeMotorCtlrIdRear;
202  m_pMotorCtlr[nCtlr] =
206 
207  m_bAreMotorsPowered = false;
208  m_bIsStopped = true;
209 
212 
213  LOGDIAG2("Created front and rear motor controllers on %s@%d.",
214  strDevName.c_str(), nBaudRate);
215  //LOGDIAG2("Front and rear motor controllers created on %s@%d, cs=%d.",
216  // strDevName.c_str(), nBaudRate, LaeGpioMotorCtlrCs);
217 
218  return LAE_OK;
219 }
RoboClaw 2 motor controller class.
Definition: RoboClaw.h:808
const int LaeGpioMotorCtlrCs
motor controler chip select gpio
Definition: laeSysDev.h:192
void * m_pEnableArg
argument to enable function
Definition: laeKin.h:514
static const int LaeMotorCtlrIdRear
rear motor controller
Definition: laeMotor.h:114
virtual void setMotorDir(int motor, int motorDir)
set the direction of motor rotation.
Definition: RoboClaw.h:943
virtual int open(std::string &strDevName, int nBaudRate, RoboClawChipSelect *pChipSelect=NULL)
Open connection to motor controller(s).
Definition: RoboClaw.cxx:234
static const int LaeMotorDirNormal
normal
Definition: laeMotor.h:136
virtual void enableMotorCtlrs()
Enable power to motor controllers.
Definition: laeKin.cxx:246
static const int LAE_ECODE_IO
I/O error.
Definition: laelaps.h:98
LaeDbRobotStatus m_robotstatus
robot status data
Definition: laeDb.h:229
static const char *const LaeKeyRear
rear
Definition: laeMotor.h:93
static const char *const LaeKeyFront
front
Definition: laeMotor.h:92
motor::roboclaw::RoboClawComm m_commMotorCtlrs
serial communication bus
Definition: laeKin.h:516
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
static const int LaeMotorLeft
left motors
Definition: laeMotor.h:128
int(* m_fnEnableMotorCtlrs)(void *, bool)
enable power function
Definition: laeKin.h:513
static const int LAE_ECODE_MOT_CTLR
motor controller error
Definition: laelaps.h:97
static const byte_t LaeMotorCtlrAddrRear
rear motor controller address
Definition: laeMotor.h:122
bool m_bInMotion
1+ motors are [not] moving
Definition: laeDb.h:112
bool m_bIsEnabled
is [not] enabled
Definition: laeKin.h:502
bool m_bIsStopped
all motors are [not] stopped
Definition: laeKin.h:504
bool m_bAreMotorsPowered
motors are [not] powered
Definition: laeKin.h:503
static const byte_t LaeMotorCtlrAddrFront
front motor controller address
Definition: laeMotor.h:120
motor::roboclaw::RoboClaw * m_pMotorCtlr[LaeNumMotorCtlrs]
RoboClaw motor controllers.
Definition: laeKin.h:518
static const int LaeMotorCtlrIdFront
front motor controller
Definition: laeMotor.h:113
static const int LaeMotorRight
right motors
Definition: laeMotor.h:129
bool m_bAreMotorsPowered
robot motors are [not] driven
Definition: laeDb.h:111
std::string getRealDeviceName(const std::string &strDevName)
Get real device name.
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinematics::plan ( )
protectedvirtual

Plan kinematic action.

Context:
Kinematics thread.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 1501 of file laeKin.cxx.

Referenced by unlock(), laelaps::LaeKinActionTwist::~LaeKinActionTwist(), and laelaps::LaeKinActionVelocity::~LaeKinActionVelocity().

1502 {
1503  int rc;
1504 
1505  // motors are not enabled
1506  if( !m_bIsEnabled )
1507  {
1508  return LAE_OK;
1509  }
1510 
1511  // planning requried, so plan
1512  else if( m_pAction->isPlanningRequired() )
1513  {
1514  rc = m_pAction->plan();
1515  }
1516 
1517  // nothing to plan
1518  else
1519  {
1520  rc = LAE_OK;
1521  }
1522 
1523  return rc;
1524 }
LaeKinAction * m_pAction
current extended kinematics action
Definition: laeKin.h:526
virtual bool isPlanningRequired()
Test if action requires (re)planning.
Definition: laeKin.h:899
bool m_bIsEnabled
is [not] enabled
Definition: laeKin.h:502
virtual int plan()
Plan next execution.
Definition: laeKin.h:854
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinematics::react ( )
protectedvirtual

React to any necessary time-critical events.

Context:
Kinematics thread.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 1496 of file laeKin.cxx.

Referenced by unlock().

1497 {
1498  return LAE_OK; // RDK TODO
1499 }
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinematics::release ( )
virtual

Release motors.

Motors will stop, but are free to roll.

Context:
Calling thread.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 1094 of file laeKin.cxx.

Referenced by freeze(), and laelaps::LaeRobot::release().

1095 {
1096  int nCtlr; // motor controller id
1097  int rc; // return code
1098 
1099  lock();
1100 
1101  if( m_bIsEnabled )
1102  {
1103  m_pAction->terminate();
1104 
1105  for(nCtlr = 0; nCtlr < LaeNumMotorCtlrs; ++nCtlr)
1106  {
1107  m_pMotorCtlr[nCtlr]->cmdDutyDrive2(0.0, 0.0);
1108  }
1109 
1110  m_bAreMotorsPowered = false;
1112 
1113  rc = LAE_OK;
1114  }
1115  else
1116  {
1117  rc = -LAE_ECODE_BAD_OP;
1118  }
1119 
1120  unlock();
1121 
1122  return rc;
1123 }
LaeKinAction * m_pAction
current extended kinematics action
Definition: laeKin.h:526
LaeDbRobotStatus m_robotstatus
robot status data
Definition: laeDb.h:229
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
virtual int cmdDutyDrive2(double duty1, double duty2)
Drive both motors at the given duty cycle.
Definition: RoboClaw.cxx:1297
bool m_bIsEnabled
is [not] enabled
Definition: laeKin.h:502
bool m_bAreMotorsPowered
motors are [not] powered
Definition: laeKin.h:503
motor::roboclaw::RoboClaw * m_pMotorCtlr[LaeNumMotorCtlrs]
RoboClaw motor controllers.
Definition: laeKin.h:518
static const int LAE_ECODE_BAD_OP
invalid operation error
Definition: laelaps.h:80
void unlock()
Unlock the shared resource.
Definition: laeKin.h:550
void lock()
Lock the shared resource.
Definition: laeKin.h:539
static const int LaeNumMotorCtlrs
number of motor controllers
Definition: laeMotor.h:115
virtual int terminate()
Terminate action.
Definition: laeKin.h:878
bool m_bAreMotorsPowered
robot motors are [not] driven
Definition: laeDb.h:111
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinematics::reload ( const LaeTunes tunes)
virtual

Reload configuration tuning parameters.

Context:
Calling thread.
Parameters
tunesLaelaps tuning parameters.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 897 of file laeKin.cxx.

Referenced by areMotorsPowered(), and laelaps::LaeThreadKin::reload().

898 {
899  LaeMapPowertrain::iterator iter; // kinematics chain iterator
900 
901  LOGDIAG2("Reloading motor controller tuning parameters...");
902 
903  for(iter = m_kinPowertrains.begin(); iter != m_kinPowertrains.end(); ++iter)
904  {
905  iter->second.reload(tunes);
906  }
907 
908  m_kinPlatform.reload(tunes);
909 
910  return LAE_OK;
911 }
LaePlatform m_kinPlatform
robot platform kinematics
Definition: laeKin.h:522
virtual int reload(const LaeTunes &tunes)
Reload tuning parameters and re-configure.
LaeMapPowertrain m_kinPowertrains
robot powertrain kinematics
Definition: laeKin.h:523
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
void LaeKinematics::resetEStop ( )
virtual

Reset emergency stop condition.

Context:
Calling thread.

Definition at line 1085 of file laeKin.cxx.

Referenced by getPowertrainMap(), and laelaps::LaeRobot::resetEStop().

1086 {
1087  lock();
1088 
1089  enableMotorCtlrs();
1090 
1091  unlock();
1092 }
virtual void enableMotorCtlrs()
Enable power to motor controllers.
Definition: laeKin.cxx:246
void unlock()
Unlock the shared resource.
Definition: laeKin.h:550
void lock()
Lock the shared resource.
Definition: laeKin.h:539
int LaeKinematics::resetMotorCtlrEncoders ( int  nCtlr)
protectedvirtual

Reset all motor controller encoders to zero.

Context:
Calling thread.
Parameters
nCtlrMotor controller id.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 643 of file laeKin.cxx.

Referenced by unlock().

644 {
645  string strTag = LaeDesc::prettyMotorCtlrName(nCtlr,
646  m_pMotorCtlr[nCtlr]->getAddress());
647 
648  int rc; // return code
649 
650  rc = m_pMotorCtlr[nCtlr]->cmdResetQEncoders();
651 
652  if( rc == OK )
653  {
654  LOGDIAG3("%s: Encoders reset.", strTag.c_str());
655  return LAE_OK;
656  }
657  else
658  {
659  LOGWARN("%s: Failed to reset encoders.", strTag.c_str());
660  return -LAE_ECODE_MOT_CTLR;
661  }
662 }
virtual int cmdResetQEncoders()
Reset both motors&#39; encoders.
Definition: RoboClaw.cxx:1152
static const int LAE_ECODE_MOT_CTLR
motor controller error
Definition: laelaps.h:97
motor::roboclaw::RoboClaw * m_pMotorCtlr[LaeNumMotorCtlrs]
RoboClaw motor controllers.
Definition: laeKin.h:518
static std::string prettyMotorCtlrName(int nCtlrId)
Create pretty motor controller identifier string.
Definition: laeDesc.cxx:596
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinematics::resetOdometers ( )
virtual

Reset all motors' odometers to the current respective encoder positions.

Context:
Calling thread.
Returns
Number of motor odometers reset.

Definition at line 1026 of file laeKin.cxx.

References laelaps::LaePowertrain::resetOdometer().

Referenced by getPowertrainMap().

1027 {
1028  int nCtlr; // motor controller id
1029  int nMotor; // motor index
1030  LaePowertrain *pTrain; // working powertrain
1031  int n; // number of powertrain odometers actually resetted
1032 
1033  lock();
1034 
1035  n = 0;
1036 
1037  if( m_bIsEnabled )
1038  {
1039  m_pAction->terminate();
1040 
1041  for(nCtlr = 0; nCtlr < LaeNumMotorCtlrs; ++nCtlr)
1042  {
1043  if( m_pMotorCtlr[nCtlr]->cmdResetQEncoders() == OK )
1044  {
1045  for(nMotor = 0; nMotor < LaeNumMotorsPerCtlr; ++nMotor)
1046  {
1047  if( (pTrain = getPowertrain(nCtlr, nMotor)) != NULL )
1048  {
1049  pTrain->resetOdometer();
1050  ++n;
1051  }
1052  }
1053  }
1054  }
1055 
1057  }
1058 
1059  unlock();
1060 
1061  return n;
1062 }
LaePowertrain * getPowertrain(const std::string &strName)
Get pointer to powertrain by name (key).
LaeKinAction * m_pAction
current extended kinematics action
Definition: laeKin.h:526
LaePlatform m_kinPlatform
robot platform kinematics
Definition: laeKin.h:522
bool m_bIsEnabled
is [not] enabled
Definition: laeKin.h:502
virtual int resetOdometer()
Reset odometry to zero.
virtual int resetOdometer()
Reset odometry to zero.
motor::roboclaw::RoboClaw * m_pMotorCtlr[LaeNumMotorCtlrs]
RoboClaw motor controllers.
Definition: laeKin.h:518
void unlock()
Unlock the shared resource.
Definition: laeKin.h:550
void lock()
Lock the shared resource.
Definition: laeKin.h:539
static const int LaeNumMotorCtlrs
number of motor controllers
Definition: laeMotor.h:115
virtual int terminate()
Terminate action.
Definition: laeKin.h:878
Powertrain data class.
static const int LaeNumMotorsPerCtlr
number of motors/controller
Definition: laeMotor.h:130
int LaeKinematics::saveConfigToNvm ( int  nCtlr)
protectedvirtual

Save configuration to motor controller's non-volatile memory.

Context:
Calling thread.
Parameters
nCtlrMotor controller id.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 874 of file laeKin.cxx.

Referenced by unlock().

875 {
876  string strTag = LaeDesc::prettyMotorCtlrName(nCtlrId,
877  m_pMotorCtlr[nCtlrId]->getAddress());
878 
879  int rc; // return code
880 
881  LOGDIAG3("%s: Saving new values to EEPROM.", strTag.c_str());
882 
883  rc = m_pMotorCtlr[nCtlrId]->cmdWriteSettingsToEEPROM();
884 
885  if( rc == OK )
886  {
887  LOGDIAG3(" Saved.");
888  }
889  else
890  {
891  LOGWARN("%s: Failed to write settings to EEPROM.", strTag.c_str());
892  }
893 
894  return LAE_OK;
895 }
virtual int cmdWriteSettingsToEEPROM()
Write all settings to EEPROM.
Definition: RoboClaw.cxx:1745
motor::roboclaw::RoboClaw * m_pMotorCtlr[LaeNumMotorCtlrs]
RoboClaw motor controllers.
Definition: laeKin.h:518
static std::string prettyMotorCtlrName(int nCtlrId)
Create pretty motor controller identifier string.
Definition: laeDesc.cxx:596
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinematics::sense ( )
protectedvirtual

Sense real-time state.

Context:
Kinematics thread.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 1423 of file laeKin.cxx.

Referenced by unlock().

1424 {
1425  int rc;
1426 
1427  // sense real-time kinodynamics
1428  rc = senseDynamics();
1429 
1430  // add other sensor reads here (e.g. imu, gps, etc).
1431 
1432  return rc;
1433 }
virtual int senseDynamics()
Sense real-time kinodynamics.
Definition: laeKin.cxx:1435
int LaeKinematics::senseDynamics ( )
protectedvirtual

Sense real-time kinodynamics.

Context:
Kinematics thread.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 1435 of file laeKin.cxx.

References iabs(), and laelaps::LaePowertrain::updateStateDynamics().

Referenced by unlock().

1436 {
1437  int nCtlr; // motor controller id
1438  int nMotor; // motor index
1439  double amp[LaeNumMotorsPerCtlr]; // motor ampere draws
1440  uint_t buflen[LaeNumMotorsPerCtlr]; // command buffer lengths
1441  s64_t encoder; // motor encoder (quad pulses)
1442  s32_t speed; // motor speed (qpps)
1443  bool bIsStopped; // all motors are [not] stopped
1444  LaePowertrain *pTrain; // working powertrain
1445 
1446  if( !m_bIsEnabled )
1447  {
1448  return LAE_OK;
1449  }
1450 
1451  bIsStopped = true;
1452 
1453  //
1454  // Sense real-time dynamics.
1455  //
1456  for(nCtlr = 0; nCtlr < LaeNumMotorCtlrs; ++nCtlr)
1457  {
1458  //
1459  // Board level sensing.
1460  //
1461  m_pMotorCtlr[nCtlr]->cmdReadMotorCurrentDraw(amp[0], amp[1]);
1462  m_pMotorCtlr[nCtlr]->cmdReadCmdBufLengths(buflen[0], buflen[1]);
1463 
1464  //
1465  // Motor level sensing.
1466  //
1467  for(nMotor = 0; nMotor < LaeNumMotorsPerCtlr; ++nMotor)
1468  {
1469  m_pMotorCtlr[nCtlr]->cmdReadQEncoder(nMotor, encoder);
1470  m_pMotorCtlr[nCtlr]->cmdReadQSpeed(nMotor, speed);
1471 
1472  if( (pTrain = getPowertrain(nCtlr, nMotor)) == NULL )
1473  {
1474  continue;
1475  }
1476 
1477  pTrain->updateStateDynamics(encoder, speed, amp[nMotor], buflen[nMotor]);
1478 
1479  if( iabs(speed) > SpeedReallyZero )
1480  {
1481  bIsStopped = false;
1482  }
1483 
1484  RtDb.m_motorctlr[nCtlr].m_fMotorCurrent[nMotor] = amp[nMotor];
1485  }
1486  }
1487 
1489 
1490  m_bIsStopped = bIsStopped;
1491  RtDb.m_robotstatus.m_bInMotion = m_bIsStopped? false: true;
1492 
1493  return LAE_OK;
1494 }
virtual int updateStateDynamics(const LaeMapPowertrain &mapPowertrains)
Update robot platform state dynamics.
LaePowertrain * getPowertrain(const std::string &strName)
Get pointer to powertrain by name (key).
virtual int updateStateDynamics(s64_t nEncoder, s32_t nSpeed, double fAmps, uint_t uBufLen)
Update state dynamics.
LaeDbRobotStatus m_robotstatus
robot status data
Definition: laeDb.h:229
virtual int cmdReadMotorCurrentDraw(double &amps1, double &amps2)
Read the motors ampere draw.
Definition: RoboClaw.cxx:761
LaePlatform m_kinPlatform
robot platform kinematics
Definition: laeKin.h:522
double m_fMotorCurrent[LaeNumMotorsPerCtlr]
motor currents (A)
Definition: laeDb.h:137
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
LaeMapPowertrain m_kinPowertrains
robot powertrain kinematics
Definition: laeKin.h:523
int iabs(int a)
Integer absolute value.
Definition: laeUtils.h:148
bool m_bInMotion
1+ motors are [not] moving
Definition: laeDb.h:112
bool m_bIsEnabled
is [not] enabled
Definition: laeKin.h:502
LaeDbMotorCtlr m_motorctlr[LaeNumMotorCtlrs]
motor controller and motor data
Definition: laeDb.h:231
bool m_bIsStopped
all motors are [not] stopped
Definition: laeKin.h:504
virtual int cmdReadQEncoder(int motor, s64_t &encoder)
Read motor&#39;s encoder.
Definition: RoboClaw.cxx:1174
motor::roboclaw::RoboClaw * m_pMotorCtlr[LaeNumMotorCtlrs]
RoboClaw motor controllers.
Definition: laeKin.h:518
virtual int cmdReadQSpeed(int motor, s32_t &speed)
Read motor&#39;s speed.
Definition: RoboClaw.cxx:1323
static const int LaeNumMotorCtlrs
number of motor controllers
Definition: laeMotor.h:115
virtual int cmdReadCmdBufLengths(uint_t &len1, uint_t &len2)
Read RoboClaw board&#39;s temperature.
Definition: RoboClaw.cxx:1075
Powertrain data class.
static const int LaeNumMotorsPerCtlr
number of motors/controller
Definition: laeMotor.h:130
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinematics::setGoalDutyCycles ( const LaeMapDutyCycle duty)
virtual

Set new or updated motor duty cycle goals.

The duty cycle actions are very simple actions (contrast with a multi-position task). Therefore, to reduce thread context switching and increase responsiveness, after the new/updated duty goals are set, the plan and execute steps are immediately called.

Context:
Calling thread.
Parameters
dutyMap of powertrain duty cycles.
Keys are left_front, right_front, left_rear, and right_rear.
Values are normalized duty cycle [-1.0, 1.0].

Definition at line 1322 of file laeKin.cxx.

References laelaps::LaeKinActionDutyCycle::execute(), laelaps::LaeKinAction::isExecutionRequired(), laelaps::LaeKinAction::isPlanningRequired(), laelaps::LaeKinAction::plan(), and laelaps::LaeKinActionDutyCycle::update().

Referenced by freeze(), and laelaps::LaeRobot::setDutyCycles().

1323 {
1324  LaeKinActionDutyCycle *pAction; // duty cycle action pointer
1325  int rc; // return code
1326 
1327  lock();
1328 
1329  if( m_bIsEnabled )
1330  {
1331  //
1332  // Current action is not a velocity action. Terminate the action and
1333  // create an this new action.
1334  //
1336  {
1339  }
1340 
1341  pAction = (LaeKinActionDutyCycle *)m_pAction;
1342 
1343  // update with new goals
1344  rc = pAction->update(duty);
1345 
1346  if( pAction->isPlanningRequired() )
1347  {
1348  rc = pAction->plan();
1349  }
1350 
1351  if( pAction->isExecutionRequired() )
1352  {
1353  if( (rc = pAction->execute()) == LAE_OK )
1354  {
1355  m_bAreMotorsPowered = true;
1357  }
1358  }
1359  }
1360  else
1361  {
1362  rc = -LAE_ECODE_BAD_OP;
1363  }
1364 
1365  unlock();
1366 
1367  return rc;
1368 }
int update(const LaeMapDutyCycle &dutycycle)
Update with new velocities.
Definition: laeKin.cxx:1877
static LaeKinAction * replaceAction(LaeKinematics &kin, LaeKinAction *pAction, const ActionType eNewActionType)
Archetype constructor to replace action type instance.
Definition: laeKin.cxx:1659
LaeKinAction * m_pAction
current extended kinematics action
Definition: laeKin.h:526
virtual ActionType getActionType() const
Get the action type for this class.
Definition: laeKin.h:932
LaeDbRobotStatus m_robotstatus
robot status data
Definition: laeDb.h:229
virtual bool isExecutionRequired() const
Test if more action requires (more) execution.
Definition: laeKin.h:909
Laelaps kinematics duty cycle action class.
Definition: laeKin.h:1042
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
virtual bool isPlanningRequired()
Test if action requires (re)planning.
Definition: laeKin.h:899
bool m_bIsEnabled
is [not] enabled
Definition: laeKin.h:502
bool m_bAreMotorsPowered
motors are [not] powered
Definition: laeKin.h:503
static const int LAE_ECODE_BAD_OP
invalid operation error
Definition: laelaps.h:80
virtual int execute()
Execution new velocities.
Definition: laeKin.cxx:1920
move by motor duty cycles
Definition: laeKin.h:784
void unlock()
Unlock the shared resource.
Definition: laeKin.h:550
void lock()
Lock the shared resource.
Definition: laeKin.h:539
bool m_bAreMotorsPowered
robot motors are [not] driven
Definition: laeDb.h:111
virtual int plan()
Plan next execution.
Definition: laeKin.h:854
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinematics::setGoalTwist ( double  fVelLinear,
double  fVelAngular 
)
virtual

Set new or updated robot twist velocity goals.

The velocity actions are very simple actions (contrast with a multi-position task). Therefore, to reduce thread context switching and increase responsiveness, after the new/updated velocity goals are set, the plan and execute steps are immediately called.

Context:
Calling thread.
Parameters
fVelLinearLinear velocity (meters/second).
fVelAngularAngular velocity (radians/second).
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 1370 of file laeKin.cxx.

References laelaps::LaeKinActionTwist::execute(), laelaps::LaeKinAction::isExecutionRequired(), laelaps::LaeKinAction::isPlanningRequired(), laelaps::LaeKinActionTwist::plan(), and laelaps::LaeKinActionTwist::update().

Referenced by freeze(), and laelaps::LaeRobot::move().

1371 {
1372  LaeKinActionTwist *pAction; // velocity action pointer
1373  int rc; // return code
1374 
1375  lock();
1376 
1377  if( m_bIsEnabled )
1378  {
1379  //
1380  // Current action is not a velocity action. Terminate the action and
1381  // create an this new action.
1382  //
1384  {
1387  }
1388 
1389  pAction = (LaeKinActionTwist *)m_pAction;
1390 
1391  // update with new goals
1392  rc = pAction->update(fVelLinear, fVelAngular);
1393 
1394  if( pAction->isPlanningRequired() )
1395  {
1396  rc = pAction->plan();
1397  }
1398 
1399  if( pAction->isExecutionRequired() )
1400  {
1401  if( (rc = pAction->execute()) == LAE_OK )
1402  {
1403  m_bAreMotorsPowered = true;
1405  }
1406  }
1407  }
1408  else
1409  {
1410  rc = -LAE_ECODE_BAD_OP;
1411  }
1412 
1413  unlock();
1414 
1415  return rc;
1416 }
static LaeKinAction * replaceAction(LaeKinematics &kin, LaeKinAction *pAction, const ActionType eNewActionType)
Archetype constructor to replace action type instance.
Definition: laeKin.cxx:1659
LaeKinAction * m_pAction
current extended kinematics action
Definition: laeKin.h:526
virtual ActionType getActionType() const
Get the action type for this class.
Definition: laeKin.h:932
LaeDbRobotStatus m_robotstatus
robot status data
Definition: laeDb.h:229
move robot by twist values
Definition: laeKin.h:785
virtual bool isExecutionRequired() const
Test if more action requires (more) execution.
Definition: laeKin.h:909
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
virtual bool isPlanningRequired()
Test if action requires (re)planning.
Definition: laeKin.h:899
bool m_bIsEnabled
is [not] enabled
Definition: laeKin.h:502
Laelaps kinematics velocity action class.
Definition: laeKin.h:1108
bool m_bAreMotorsPowered
motors are [not] powered
Definition: laeKin.h:503
static const int LAE_ECODE_BAD_OP
invalid operation error
Definition: laelaps.h:80
int update(double fVelLinear, double fVelAngular)
Update with new velocities.
Definition: laeKin.cxx:2029
void unlock()
Unlock the shared resource.
Definition: laeKin.h:550
void lock()
Lock the shared resource.
Definition: laeKin.h:539
virtual int execute()
Execution new velocities.
Definition: laeKin.cxx:2159
bool m_bAreMotorsPowered
robot motors are [not] driven
Definition: laeDb.h:111
virtual int plan()
Plan next execution.
Definition: laeKin.cxx:2053
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinematics::setGoalVelocities ( const LaeMapVelocity velocity)
virtual

Set new or updated motor velocity goals.

The velocity actions are very simple actions (contrast with a multi-position task). Therefore, to reduce thread context switching and increase responsiveness, after the new/updated velocity goals are set, the plan and execute steps are immediately called.

Context:
Calling thread.
Parameters
velocityMap of powertrain velocities.
Keys are left_front, right_front, left_rear, and right_rear.
Values are wheel shaft angular velocities (radians/second).

Definition at line 1274 of file laeKin.cxx.

References laelaps::LaeKinActionVelocity::execute(), laelaps::LaeKinAction::isExecutionRequired(), laelaps::LaeKinAction::isPlanningRequired(), laelaps::LaeKinActionVelocity::plan(), and laelaps::LaeKinActionVelocity::update().

Referenced by freeze(), and laelaps::LaeRobot::move().

1275 {
1276  LaeKinActionVelocity *pAction; // velocity action pointer
1277  int rc; // return code
1278 
1279  lock();
1280 
1281  if( m_bIsEnabled )
1282  {
1283  //
1284  // Current action is not a velocity action. Terminate the action and
1285  // create an this new action.
1286  //
1288  {
1291  }
1292 
1293  pAction = (LaeKinActionVelocity *)m_pAction;
1294 
1295  // update with new goals
1296  rc = pAction->update(velocity);
1297 
1298  if( pAction->isPlanningRequired() )
1299  {
1300  rc = pAction->plan();
1301  }
1302 
1303  if( pAction->isExecutionRequired() )
1304  {
1305  if( (rc = pAction->execute()) == LAE_OK )
1306  {
1307  m_bAreMotorsPowered = true;
1309  }
1310  }
1311  }
1312  else
1313  {
1314  rc = -LAE_ECODE_BAD_OP;
1315  }
1316 
1317  unlock();
1318 
1319  return rc;
1320 }
static LaeKinAction * replaceAction(LaeKinematics &kin, LaeKinAction *pAction, const ActionType eNewActionType)
Archetype constructor to replace action type instance.
Definition: laeKin.cxx:1659
LaeKinAction * m_pAction
current extended kinematics action
Definition: laeKin.h:526
virtual int execute()
Execution new velocities.
Definition: laeKin.cxx:1785
virtual ActionType getActionType() const
Get the action type for this class.
Definition: laeKin.h:932
LaeDbRobotStatus m_robotstatus
robot status data
Definition: laeDb.h:229
virtual bool isExecutionRequired() const
Test if more action requires (more) execution.
Definition: laeKin.h:909
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
virtual bool isPlanningRequired()
Test if action requires (re)planning.
Definition: laeKin.h:899
int update(const LaeMapVelocity &velocity)
Update with new velocities.
Definition: laeKin.cxx:1683
bool m_bIsEnabled
is [not] enabled
Definition: laeKin.h:502
bool m_bAreMotorsPowered
motors are [not] powered
Definition: laeKin.h:503
static const int LAE_ECODE_BAD_OP
invalid operation error
Definition: laelaps.h:80
void unlock()
Unlock the shared resource.
Definition: laeKin.h:550
void lock()
Lock the shared resource.
Definition: laeKin.h:539
move by angular velocities
Definition: laeKin.h:783
virtual int plan()
Plan next execution.
Definition: laeKin.cxx:1727
bool m_bAreMotorsPowered
robot motors are [not] driven
Definition: laeDb.h:111
Laelaps kinematics velocity action class.
Definition: laeKin.h:966
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
int LaeKinematics::stop ( )
virtual

Stop all motors at the current position.

The motor brakes, if available, are applied.

Note
The current RoboClaw motor controllers do not have electrical braking and the current Laelaps versions do not have mechanical braking.
Context:
Calling thread.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 1125 of file laeKin.cxx.

Referenced by laelaps_tune_motors.window::createLeftButtons(), laelaps::LaeRobot::freeze(), and freeze().

1126 {
1127  int nCtlr; // motor controller id
1128  int rc; // return code
1129 
1130  lock();
1131 
1132  if( m_bIsEnabled )
1133  {
1134  m_pAction->terminate();
1135 
1136  for(nCtlr = 0; nCtlr < LaeNumMotorCtlrs; ++nCtlr)
1137  {
1138  //m_pMotorCtlr[nCtlr]->cmdQStop();
1139  m_pMotorCtlr[nCtlr]->cmdStopWithDecel(StopDecel);
1140  }
1141 
1142  m_bAreMotorsPowered = true;
1144 
1145  rc = LAE_OK;
1146  }
1147  else
1148  {
1149  rc = -LAE_ECODE_BAD_OP;
1150  }
1151 
1152  unlock();
1153 
1154  return rc;
1155 }
LaeKinAction * m_pAction
current extended kinematics action
Definition: laeKin.h:526
LaeDbRobotStatus m_robotstatus
robot status data
Definition: laeDb.h:229
LaeDb RtDb
The real-time database.
Definition: laeDb.h:244
bool m_bIsEnabled
is [not] enabled
Definition: laeKin.h:502
bool m_bAreMotorsPowered
motors are [not] powered
Definition: laeKin.h:503
motor::roboclaw::RoboClaw * m_pMotorCtlr[LaeNumMotorCtlrs]
RoboClaw motor controllers.
Definition: laeKin.h:518
static const int LAE_ECODE_BAD_OP
invalid operation error
Definition: laelaps.h:80
void unlock()
Unlock the shared resource.
Definition: laeKin.h:550
void lock()
Lock the shared resource.
Definition: laeKin.h:539
virtual int cmdStopWithDecel(int motor, u32_t decel)
Stop a motor with the given maximum decelerations.
Definition: RoboClaw.cxx:1711
static const int LaeNumMotorCtlrs
number of motor controllers
Definition: laeMotor.h:115
virtual int terminate()
Terminate action.
Definition: laeKin.h:878
bool m_bAreMotorsPowered
robot motors are [not] driven
Definition: laeDb.h:111
static const int LAE_OK
not an error, success
Definition: laelaps.h:71
virtual int laelaps::LaeKinematics::stop ( const std::vector< std::string > &  vecNames)
virtual

Stop the set of powertrain motors at the current position.

Context:
Calling thread.
Parameters
vecNameVector of unique powertrain names.
Returns
Number of powertrain motors stopped.

Referenced by laelaps_tune_motors.window::createLeftButtons().

virtual int laelaps::LaeKinematics::stop ( const std::string &  strName)
virtual

Stop one powertrain motor at the current position.

Context:
Calling thread.
Parameters
strNamePowertrain unique name.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Referenced by laelaps_tune_motors.window::createLeftButtons().

void laelaps::LaeKinematics::unlock ( )
inlineprotected
int LaeKinematics::waitForAllStop ( double  fSeconds)
virtual

Wait for all motors to stop.

Context:
Calling thread.
Parameters
fSecondsMaximum number of seconds to wait.
Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 1253 of file laeKin.cxx.

Referenced by freeze().

1254 {
1255  static const useconds_t WaitDt = 100; // usec wait between tests
1256 
1257  int nMaxTries = (int)ceil(fSeconds * MILLION / (double)WaitDt);
1258 
1259  for(int i = 0; i < nMaxTries; ++i)
1260  {
1261  if( isStopped() )
1262  {
1263  return LAE_OK;
1264  }
1265  usleep(WaitDt);
1266  }
1267 
1268  LOGERROR("Timed out waiting for %.2lf seconds for all joints to stop.",
1269  fSeconds);
1270 
1271  return -LAE_ECODE_TIMEDOUT;
1272 }
virtual bool isStopped()
Test if all motors are stopped.
Definition: laeKin.cxx:986
static const int LAE_ECODE_TIMEDOUT
operation timed out error
Definition: laelaps.h:81
static const int LAE_OK
not an error, success
Definition: laelaps.h:71

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