56 #include "rnr/rnrconfig.h" 57 #include "rnr/units.h" 112 #define LAE_TRY_NO_EXEC() \ 129 #define LAE_TRY_CONN() \ 132 if( !isConnected() ) \ 134 LOGERROR("Robot is not connected."); \ 135 return -LAE_ECODE_NO_EXEC; \ 147 #define LAE_TRY_NOT_ESTOP() \ 150 if( m_bIsEStopped ) \ 152 LOGERROR("Robot is emergency stopped."); \ 153 return -LAE_ECODE_NO_EXEC; \ 162 const double LaeRobot::GovernorDft = 1.0;
164 LaeRobot::LaeRobot(
bool bNoExec) :
165 m_i2cBus(), m_watchdog(m_i2cBus), m_range(m_i2cBus),
168 m_threadRange(m_range),
169 m_threadWatchDog(m_watchdog)
206 LOGWARN(
"Laelaps already connected to hardware.");
217 LOGERROR(
"Undefined Laelaps description - " 218 "don't know how to initialized properly.");
254 LOGSYSERROR(
"Failed to opend I2C bus.");
311 LOGERROR(
"Failed to connect and/or initialize hardware.");
327 LOGDIAG1(
"Connected to Laelaps.");
367 LOGDIAG1(
"Disconnected from Laelaps.");
383 LOGERROR(
"Failed to reload kinodynamics tune parameters.");
390 LOGERROR(
"Failed to reload IMU tune parameters.");
397 LOGERROR(
"Failed to reload range sensing tune parameters.");
404 LOGERROR(
"Failed to reload WatchDog tune parameters.");
410 LOGDIAG2(
"Reloaded tuning parameters and reconfigured robot.");
439 LOGDIAG3(
"Laelaps emergency stopped.");
445 LOGERROR(
"Failed to emergency stop.");
469 LOGDIAG3(
"Laelaps emergency stopped reset.");
475 LOGERROR(
"Failed to reset emergency stopped condition.");
495 LOGDIAG3(
"Laelaps frozen at current position.");
511 LOGDIAG3(
"Laelaps motor drives released.");
579 if( strName ==
"aux_batt_en" )
584 else if( strName ==
"aux_5v_en" )
591 LOGERROR(
"%s: Unknown auxilliary port name.", strName.c_str());
607 rptBotStatus.
clear();
644 string &strRadiationType,
672 vector<double> &vecAmbient)
697 pathFeedback.
clear();
706 pathFeedback.
clear();
793 bool bAlarmState =
false;
852 uint_t uVerMajor, uVerMinor, uFwVer;
865 LOGERROR(
"%s: Failed to read IMU identity.",
LaeDevIMU);
870 LOGDIAG2(
"Connected to IMU %s.", strIdent.c_str());
875 LOGWARN(
"IMU is blacklisted from the suite of robot sensors.");
884 LOGERROR(
"Failed to set range sensor group interface.");
889 LOGERROR(
"Failed to read range sensor group interface version.");
896 LOGDIAG2(
"Connected to Range Sensor Group v%u.%u, fwver=%u.",
897 uVerMajor, uVerMinor, uFwVer);
902 LOGWARN(
"Range sensors are blacklisted from the suite of robot sensors.");
915 LOGWARN(
"WatchDog: Failed to get firmware version.");
919 LOGDIAG2(
"Connected to WatchDog sub-processor, fwver=%u.", uFwVer);
933 rc =
m_kin.
open(strDevMotorCtlrs, nBaudRate,
938 LOGERROR(
"%s: Failed to open at motor controllers at %d baud.",
939 strDevMotorCtlrs.c_str(), nBaudRate);
942 LOGDIAG2(
"Created front and rear motor controller interfaces.");
956 LOGERROR(
"Failed to configure WatchDog.");
964 LOGERROR(
"Failed to tune WatchDog.");
972 LOGERROR(
"Failed to configure kinodynamics.");
980 LOGERROR(
"Failed to tune kinodynamics.");
988 LOGERROR(
"Failed to configure IMU.");
996 LOGERROR(
"Failed to tune IMU.");
1004 LOGERROR(
"Failed to configure IMU.");
1012 LOGERROR(
"Failed to configure range sensor group.");
1030 LOGDIAG2(
"Configured for operation.");
1097 LOGERROR(
"%s thread: Failed to create.", strName.c_str());
1099 else if( (rc = pThread->
runThread(fHz)) < 0 )
1101 LOGERROR(
"%s thread: Failed to start.", strName.c_str());
1105 LOGDIAG2(
"%s thread started at %.3lfHz with priority %d.",
1106 strName.c_str(), fHz, nPriority);
int open(const std::string &strDevMotorCtlrs, const int nBaudRate, int(*fnEnable)(void *, bool)=NULL, void *pEnableArg=NULL)
Open communication with the <b><i>Laelaps</i></b> motor controllers.
int getAsyncJobRc()
Get the last asynchronous job exit return code.
double m_fGovernor
speed limit governor setting
std::map< std::string, double > LaeMapDutyCycle
Duty cycle trajectory type.
virtual int terminateThread()
Terminate the thread.
virtual int configure(const laelaps::LaeDesc &desc)
Configure IMU from product description.
int startCoreThreads()
Create and start all real-time persistent core threads.
double getImuHz() const
Get IMU tasks thread cycle rate tune parameter (hertz).
JobState getState()
Get the current job state.
uint_t getProdHwVer() const
Get this robot's packed hardware version number.
#define LAE_TRY_NO_EXEC()
Test for no execute flag.
virtual int cmdReadDPin(uint_t pin, uint_t &val)
Read the value of a digital pin command.
virtual bool areMotorsPowered()
Test if motors are powered.
bool m_bIsEStopped
robot is [not] emergency stopped
virtual int getRange(const std::string &strKey, double &fRange)
Get the shadowed range measurement.
virtual int terminateThread()
Terminate the thread.
virtual int stop()
Stop all motors at the current position.
std::string getFullProdBrief()
Get the <b><i>Laelaps</i></b> full brief descirption.
int reload(const LaeTunes &tunes)
Reload tunable paramaters.
double getWatchDogTimeout() const
Get watchdog timeout (seconds).
Laelaps kinodynamics thread class interface.
virtual int runThread(const double fHz=ThreadAsyncHzDft)
Run the thread.
std::string getProdName()
Convenience function to get this <b><i>Laelaps</i></b> description's base product name...
int setAuxPower(const std::string &strName, LaeTriState eState)
Set top deck auxilliary power out enable state.
LaeXmlTune <b><i>Laelaps</i></b> XML tuning class.
Trajectory classes interfaces.
const char *const LaeEtcTune
xml tune file
Laelaps robotic mobile platform full description class.
void clearSensedData()
Clear sensed data.
int resetEStop()
Reset (clears) emergency stop condition.
LaePowertrain * getPowertrain(const std::string &strName)
Get pointer to powertrain by name (key).
double getKinematicsHz() const
Get kinematics thread cycle rate tune parameter (hertz).
#define LAE_VER_REV(ver)
Get revision number from version.
LaeThreadImu m_threadImu
IMU thread.
virtual bool isEnabled()
Test if motors are enabled.
bool isEStopped()
Test if robot is current emergency stopped.
static bool isSafeToOperate()
Test if robot is safe to operate given the current alarm state.
LaeThreadAsync m_threadAsync
asynchronous action thread
virtual int open(const std::string &strDevName, int nBaudRate)
const int LaeBaudRateMotorCtlrs
motor controller serial baudrate
int connect()
Connect to <b><i>Laelaps</i></b>.
int connSensors()
Connect to the <b><i>Laelaps</i></b> built-in sensors.
sensor::imu::LaeImuCleanFlight m_imu
inertia measurement unit
#define LAE_VER_MINOR(ver)
Get version minor number from version.
virtual int readDigitalPin(uint_t pin, uint_t &val)
Read the value of a digital pin on the watchdog subprocessor.
static const u32_t LAE_ALARM_NONE
no alarms
virtual int getRangeSensorProps(const std::string &strKey, std::string &strRadiationType, double &fFoV, double &fBeamDir, double &fMin, double &fMax)
Get range sensor properties.
LaeRobotMode
<b><i>Laelaps</i></b> mode of operation.
static double optimizeHz(const double fWatchDogTimeout)
Optimize thread hertz rate given the watchdog timeout value.
double fcap(double a, double min, double max)
Cap value within limits [min, max].
void cancelAsyncJob()
Cancel any asynchronous job.
LaeDbRobotStatus m_robotstatus
robot status data
LaePowertrain * getPowertrain(const std::string &strName)
Get the robotic joint in kinematic chain.
virtual int cmdWriteDPin(uint_t pin, uint_t val)
Write a value to a digital pin command.
LaeWd m_watchdog
watchdog sub-processor
virtual int configure(const LaeDesc &desc)
Configure watchdog from product description.
virtual int setGoalVelocities(const LaeMapVelocity &velocity)
Set new or updated motor velocity goals.
static const double ThreadWdPrioDft
default priority
virtual int getInterfaceVersion(uint_t &uVerMajor, uint_t &uVerMinor, uint_t &uFwVer)
Get interface version.
static const double ThreadRangePrioDft
default priority
virtual int setGoalTwist(double fVelLinear, double fVelAngular)
Set new or updated robot twist velocity goals.
LaeRobotMode getRobotMode()
Get robot's operational mode.
RoboClaw motor controller class interface.
int startThread(LaeThread *pThread, int nPriority, double fHz)
Create and start a thread at the given priority and hertz.
virtual void clearSensedData()
Clear IMU sensed data.
bool canMove()
Test if robot is safe to operate, given the current robot and alarm state.
Laelaps WatchDog software class interface.
Laelaps PCA9548A I2C multiplexer switch interface.
double setGovernor(double fGovernor)
Set speed limit governor value.
int getRobotStatus(LaeRptRobotStatus &rptBotStatus)
Get the robot current status.
LaeDesc m_descLaelaps
<b><i>Laelaps</i></b> description
LaeDb RtDb
The real-time database.
bool isDescribed()
Test if robot is fully described via configuration XML.
static const double GovernorDft
speed limit governor start-up default
virtual int configDigitalPin(uint_t pin, uint_t dir)
Configure a digital pin on the the watchdog subprocessor.
LaeThreadKin m_threadKin
kinodynamics thread
LaeDesc & getLaelapsDesc()
Get the <b><i>Laelaps</i></b> product description.
Laelaps I2C class interface.
virtual int cmdEnableAuxPort5V(bool bEnable)
Enable/disable regulated 5 volt auxilliary port power out.
LaeAlarmInfo m_system
system alarm summary state
int configForOperation()
Configure <b><i>Laelaps</i></b> for normal operation.
Simple path feedback class.
std::string getProdBrief() const
Get this base description's brief.
virtual int configure(const LaeDesc &desc)
Configure kinematics chains and data from product description.
virtual void getImuData(double accel[], double gyro[], double mag[], double rpy[], Quaternion &q)
Get the last sensed, converted, and computed IMU data.
const char *const LaeSysCfgPath
System configuration search path.
virtual bool isStopped()
Test if all motors are stopped.
virtual int getRange(const std::string &strKey, double &fRange)
Get a range measurement.
LaeRobotMode m_eRobotMode
robot operating mode
int reload(const LaeTunes &tunes)
Reload tunable paramaters.
bool m_bIsConnected
critical hardware [not] connected
LaeTunes m_tunes
tuning parameters
void clear()
Clear report.
static const int LAE_ECODE_MOT_CTLR
motor controller error
int getProdId() const
Get this base description's base product id.
virtual int configure(const laelaps::LaeDesc &desc)
Configure sensor group from product description.
<b><i>Laelaps</i></b> XML tuning class interface.
Laelaps Time-of-Flight sensors. The ToFs are used as a virtual bumper for close-in obstacle detection...
static const double ThreadKinPrioDft
default priority
bool isDescribed() const
Test if required base description is adequately described.
int disconnect()
Disconnect from <b><i>Laelaps</i></b>.
const byte_t LaeI2CAddrWd
watchdog I2C address synonym
int reload()
Reload <b><i>Laelaps</i></b>'s reloadable configuration and reset operational parameters.
int estop()
Emergency stop.
virtual int load(LaeTunes &tunes, const std::string &strSearchPath=LaeSysCfgPath, const std::string &strXmlFileName=LaeEtcTune, bool bAllInstances=false)
Load XML file into DOM and set the <b><i>Laelaps</i></b> tuning parameters.
The <b><i>Laelaps</i></b> namespace encapsulates all <b><i>Laelaps</i></b> related constructs...
Interfaces of Laelaps requested and/or published report classes.
Laelaps robotic base mobile platform description class interface.
bool m_bIsConnected
critical hardware [not] connected
void generate(LaeRobot *pRobot)
Generate report.
double getGovernor()
Get current speed limit governor setting.
int connMotorControllers(const std::string &strDevMotorCtlrs, const int nBaudRate)
Connect to the <b><i>Laelaps</i></b> motor controllers.
LaeAsyncJob::JobState getAsyncJobState()
Get the current asynchronous job state.
void syncDb()
Synchronize real-time database with current robot state.
virtual void resetEStop()
Reset emergency stop condition.
const int NumOfAxes
maximum number of axes per sensor component.
double incrementGovernor(double fDelta)
Increment/decrement speed limit governor value.
#define LAE_TRY_CONN()
Test for connection.
Laelaps common utilities.
sensor::vl6180::LaeRangeSensorGroup m_range
range sensor group.
const int LaeBaudRateIMU
IMU serial baudrate.
Laelaps built-in Inertial Measurement Unit class interface.
Simple path feedback class.
std::string getVersionString()
Get the <b><i>Laelaps</i></b> robotic arm hardware version string.
bool isAlarmed()
Test if robot is alarmed.
LaeI2C m_i2cBus
I2C sensor bus.
The Laelaps kinematics and dynamics class interface.
Laelaps powertrain class interfaces.
int freeze()
Freeze robot and accessories at current position.
u32_t m_uAlarms
alarm or'ed bits
const char *const LaeDevIMU
IMU USB udev linked name.
virtual int cmdReadAPin(uint_t pin, uint_t &val)
Read the value of an analog pin command.
virtual int getImu(double accel[], double gyro[], double rpy[], sensor::imu::Quaternion &q)
Get the last read and converted inertia data.
bool m_bIsEStopped
robot is [not] emergency stopped
int getProdId()
Convenience function to get this <b><i>Laelaps</i></b> description's base product id...
virtual int createThread(int nPriority)
Create the thread.
Laelasp Robot Class interface.
std::string getThreadName() const
Get assigned thread name.
LaeThreadRange m_threadRange
ToF range sensors thread.
virtual int getAmbientLight(const std::string &strKey, double &fAmbient)
Get an ambient light illuminance measurement.
int getDynamics(LaeRptDynamics &rptDynamics)
Get the robot full dynamic state.
static const int LAE_ECODE_BAD_OP
invalid operation error
static const int LAE_ECODE_NO_RSRC
no resource available error
int getNavigationState(LaeSimplePathFeedback &pathFeedback)
Get simple navigation feedback.
int getRc()
Get job's return code.
bool m_bNoExec
do [not] execute physical movements
Laelaps built-in Arduino sub-processor.
virtual int cmdGetFwVersion(uint_t &uVerNum)
Get the firmware version command.
virtual void blacklist()
Black list range sensor group from robot sensors.
Laelaps range sensors thread class interface.
virtual ~LaeRobot()
Destructor.
int connWatchDog()
Connect to the watchdog subprocessor.
bool isInMotion()
Test if any joint in any of the kinematic chains is moving.
virtual int setGoalDutyCycles(const LaeMapDutyCycle &duty)
Set new or updated motor duty cycle goals.
Laelaps asynchronouse thread class interface.
Laelaps motors, encoder, and controllers hardware abstraction interfaces.
Laelaps watchdog thread class interface.
int setInterface(uint_t uProdHwVer)
Set the interface, given the <b><i>Laelaps</i></b> hardware version.
static const int LAE_ECODE_BAD_VAL
bad value general error
Laelaps alarm monitoring class interface.
bool areMotorsPowered()
Test if robot motor are currently being driven (powered).
bool m_bAlarmState
robot is [not] alarmed
int clearAlarms()
Attempt to clear all alarms.
int reload(const LaeTunes &tunes)
Reload tunable paramaters.
virtual int close()
Close communication.
Robot global status report.
virtual int createThread(LaeAsyncJob *pJob, int nPriority=ThreadAsyncPrioDft)
Create the thread.
#define LAE_VER_MAJOR(ver)
Get version major number from version.
virtual int cmdConfigDPin(uint_t pin, uint_t dir)
Configure a digital pin command.
int setDutyCycles(const LaeMapDutyCycle &duty)
Set powertrain motor duty cycles.
void setRobotMode(LaeRobotMode eRobotMode)
Set robot's operational mode.
void getVersion(int &nVerMajor, int &nVerMinor, int &nRevision)
Get the <b><i>Laelaps</i></b> hardware version number.
int move(const LaeMapVelocity &velocity)
Move by setting powertrain angular wheel velocities.
LaeDbAlarms m_alarms
alarm state data
Laelaps IMU thread class interface.
virtual int readIdentity(std::string &strIdent)
Read sensor identity values.
virtual int release()
Release motors.
LaeKinematics m_kin
robot base dynamics and kinematics
bool m_bAlarmState
robot is [not] alarmed
Laelaps supported cameras.
virtual int getAmbientLight(const std::string &strKey, double &fAmbient)
Get the shadowed ambient light illuminance measurement.
std::string getProdHwVerString() const
Get this robot's hardware version string.
int release()
Release robot and accessories.
virtual int close()
Close I2C bus device.
LaeAsyncJob * m_pAsyncJob
asynchronous job
virtual int runThread(const double fHz)
Run the thread.
std::map< std::string, double > LaeMapVelocity
Velocity trajectory type.
int stop()
Stop robot with full dynamic braking.
virtual int readAnalogPin(uint_t pin, uint_t &val)
Read the value of an analog pin on the watchdog subprocessor.
std::string getProdName() const
Get this base description's name.
virtual int getSensorProps(const std::string &strKey, std::string &strRadiationType, double &fFoV, double &fBeamDir, double &fMin, double &fMax)
Get range sensor properties.
virtual int close()
Close connection to motor controller.
int i2cTryOpen(LaeI2C &i2cBus, uint_t addr)
Try to open a series of I2C devices to fine the required endpoint.
static int enableMotorCtlrs(void *pArg, bool bEnable)
Enable/disable power in to motor controllers.
virtual int cmdEnableAuxPortBatt(bool bEnable)
Enable/disable battery auxilliary port power out.
static const double ThreadImuPrioDft
default priority
LaeTriState
<b><i>Laelaps</i></b> tri-state type.
bool isConnected()
Test if connected to <b><i>Laelaps</i></b> hardware.
double getRangeHz() const
Get range sensing thread cycle rate tune parameter (hertz).
void generate(LaeRobot *pRobot)
Generate report.
Laelaps real-time "database".
int runAsyncJob()
Run asynchronous job.
const char *const LaeDevMotorCtlrs
odroid motor controllers' serial device name
LaeThreadWd m_threadWatchDog
watchdog thread
void clear()
Clear report.
int reload(const LaeTunes &tunes)
Reload tunable paramaters.
virtual void blacklist()
Black list IMU from robot sensors.
virtual void sync()
Synchronize watchdog state with subprocessor state.
virtual void estop()
Emergency stop the robot.
Top-level package include file.
LaeRobotMode m_eRobotMode
robot operating mode
static const int LAE_OK
not an error, success
virtual int writeDigitalPin(uint_t pin, uint_t val)
Write a value to a digital pin on the watchdog subprocessor.