54 #include "rnr/rnrconfig.h" 76 LaePowertrainAttr::LaePowertrainAttr()
79 m_nMotorId = LaeMotorIdNone;
80 m_nMotorCtlrId = LaeMotorCtlrIdNone;
83 m_nMotorDir = LaeMotorDirNormal;
84 m_eJointType = LaeJointTypeUnknown;
86 m_uPulsesPerRev = 0.0;
90 m_fMotorRadsPerPulse = 0.0;
91 m_fWheelRadsPerPulse = 0.0;
98 m_fMetersPerPulse = 0.0;
99 m_fMetersPerRadian = 0.0;
160 LaePowertrainState::LaePowertrainState()
168 m_uAlarms = LaeMotorAlarmNone;
169 m_uWarnings = LaeMotorWarnNone;
220 LaePowertrain::LaePowertrain()
240 int LaePowertrain::toMotorId(
const int nCtlrId,
const int nMotorIndex)
244 case LaeMotorCtlrIdFront:
245 switch( nMotorIndex )
255 case LaeMotorCtlrIdRear:
256 switch( nMotorIndex )
270 return LaeMotorIdNone;
273 string LaePowertrain::toKey(
const int nCtlrId,
const int nMotorIndex)
275 static const char *unknown =
"";
277 int nMotorId = LaePowertrain::toMotorId(nCtlrId, nMotorIndex);
279 return nMotorId != LaeMotorIdNone? LaeDesc::KeyPowertrain[nMotorId]: unknown;
282 string LaePowertrain::toKey(
const int nMotorId)
284 static const char *unknown =
"";
286 if( (nMotorId >= 0) && (nMotorId < LaeMotorsNumOf) )
288 LaeDesc::KeyPowertrain[nMotorId];
304 m_attr.m_nMotorDir = desc.
m_nDir;
308 m_attr.m_uPulsesPerRev = LaeQuadPulsesPerRev;
309 m_attr.m_fMaxRps = LaeMotorRatedMaxRpm / 60.0;
310 m_attr.m_uMaxQpps = (uint_t)(
312 m_attr.m_fGearRatio *
313 (
double)m_attr.m_uPulsesPerRev);
315 m_attr.m_fMotorRadsPerPulse =
M_TAU / (double)m_attr.m_uPulsesPerRev;
316 m_attr.m_fWheelRadsPerPulse = m_attr.m_fMotorRadsPerPulse /
319 m_attr.m_fMaxAmps = LaeMotorRatedAmps;
320 m_attr.m_fStallTorque = LaeMotorStallTorque;
325 int LaePowertrain::configure(
const LaeTunes &tunes)
327 double fTuneTireRadius, fTuneTireWidth;
331 m_attr.m_fTireRadius = fTuneTireRadius;
332 m_attr.m_fTireWidth = fTuneTireWidth;
334 m_attr.m_fMetersPerPulse = m_attr.m_fWheelRadsPerPulse * m_attr.m_fTireRadius;
335 m_attr.m_fMetersPerRadian = m_attr.m_fTireRadius;
342 return configure(tunes);
345 int LaePowertrain::resetOdometer()
347 m_state.m_nEncoder = 0;
348 m_state.m_fPosition = 0.0;
350 RtDb.m_kin.m_powertrain[m_attr.m_nMotorId].m_fPosition = m_state.m_fPosition;
353 int LaePowertrain::updateStateDynamics(s64_t nEncoder,
358 m_state.m_nEncoder = nEncoder;
359 m_state.m_nSpeed = nSpeed;
363 m_state.m_fAmps = fAmps;
367 m_state.m_uBufLen = uBufLen;
370 m_state.m_fPosition = (double)m_state.m_nEncoder *
371 m_attr.m_fWheelRadsPerPulse;
372 m_state.m_fVelocity = (
double)m_state.m_nSpeed *
373 m_attr.m_fWheelRadsPerPulse;
376 m_state.m_fPe = m_state.m_fAmps * m_state.m_fVolts;
377 m_state.m_fPm = m_state.m_fPe * 1.0;
380 if( fabs(m_state.m_fVelocity) >= 0.0001 )
382 m_state.m_fTorque = m_state.m_fPm / m_state.m_fVelocity;
384 else if( m_state.m_fAmps >= (m_attr.m_fMaxAmps * 0.9) )
386 m_state.m_fTorque = m_attr.m_fStallTorque *
392 m_state.m_fTorque = 0.0;
395 m_state.m_fTorque =
fcap(m_state.m_fTorque, -m_attr.m_fStallTorque,
396 m_attr.m_fStallTorque);
399 RtDb.m_kin.m_powertrain[m_attr.m_nMotorId].m_nEncoder = m_state.m_nEncoder;
400 RtDb.m_kin.m_powertrain[m_attr.m_nMotorId].m_nSpeed = m_state.m_nSpeed;
401 RtDb.m_kin.m_powertrain[m_attr.m_nMotorId].m_fPosition = m_state.m_fPosition;
402 RtDb.m_kin.m_powertrain[m_attr.m_nMotorId].m_fVelocity = m_state.m_fVelocity;
403 RtDb.m_kin.m_powertrain[m_attr.m_nMotorId].m_fPe = m_state.m_fPe;
404 RtDb.m_kin.m_powertrain[m_attr.m_nMotorId].m_fTorque = m_state.m_fTorque;
407 int LaePowertrain::updateHealth(
double fVolts,
double fTemp, uint_t uCtlrStatus)
409 m_state.m_fVolts = fVolts;
410 m_state.m_fTemp = fTemp;
412 m_state.m_uAlarms = LaeMotorAlarmNone;
413 m_state.m_uWarnings = LaeMotorWarnNone;
423 m_state.m_uAlarms |= LaeMotorAlarmEStop;
429 m_state.m_uAlarms |= LaeMotorAlarmTemp;
435 m_state.m_uWarnings |= LaeMotorWarnTemp;
443 m_state.m_uAlarms |= LaeMotorAlarmVoltage;
450 m_state.m_uWarnings |= LaeMotorWarnVoltage;
453 if( m_attr.m_nMotorIndex == Motor1 )
458 m_state.m_uAlarms |= LaeMotorAlarmFault;
464 m_state.m_uWarnings |= LaeMotorWarnCurrent;
467 else if( m_attr.m_nMotorIndex == Motor2 )
472 m_state.m_uAlarms |= LaeMotorAlarmFault;
478 m_state.m_uWarnings |= LaeMotorWarnCurrent;
484 m_state.m_fTorque = 0.0;
486 m_state.m_fPe = m_state.m_fAmps * m_state.m_fVolts;
487 m_state.m_fPm = m_state.m_fPe * 1.0;
logic battery under volt error
double m_fAmps
motor draw (A)
int m_nMotorCtlrId
motor controller id
Laelaps tuning data class.
double m_fTemp
motor temperature (C)
int m_eJointType
joint type
uint_t m_uBufLen
command queue length
double m_fGearRatio
gear ratio
double fcap(double a, double min, double max)
Cap value within limits [min, max].
double m_fTorque
wheel torque (N-m)
double m_fMaxAmps
maximum rated amps
std::string m_strName
powertrain unique name (key)
int m_nMotorIndex
motor controller unique motor index
RoboClaw motor controller class interface.
double m_fMaxRps
maximum rated output shaft rev/sec
int m_nMotorDir
motor normalized direction
double m_fTireRadius
tire radius
double m_fPm
motor output mechanical power (W)
LaeJointType m_eJointType
powertrain joint type
double m_fMotorRadsPerPulse
motor radians per encoder pulse
temperature out-of-range error
uint_t m_uWarnings
motor warnings
int m_nDir
normalize cw/ccw direction.
Powertrain attributes class.
double m_fStallTorque
stall torque amps
LaePowertrainAttr m_attr
semi-fixed attribute data
Robotic powertrain description.
main battery over voltage error
The <b><i>Laelaps</i></b> namespace encapsulates all <b><i>Laelaps</i></b> related constructs...
Laelaps robotic base mobile platform description class interface.
uint_t m_uMaxQpps
maximum quadrature pulses/second rps
temp out-of-range warning
uint_t m_uAlarms
motor alarms
Laelaps common utilities.
double m_fVolts
input motor voltage (V)
main battery over volt warning
Laelaps powertrain class interfaces.
int m_nMotorId
unique robot motor id
s64_t m_nEncoder
motor encoder position (quad pulses)
double m_fMetersPerRadian
tire meters per radian
double m_fGearRatio
motor gear ratio
main battery under volt warning
double m_fMetersPerPulse
tire meters per encoder pulse
int m_nMotorCtlrId
unique motor controller id
Laelaps motors, encoder, and controllers hardware abstraction interfaces.
logic battery over volt error
std::string m_strKey
powertrain key
motor 1 over current warning
double m_fWheelRadsPerPulse
output shaft radians per encoder pulse
Powertrain state data class.
LaePowertrainState m_state
dynamic state data
double m_fPe
motor input electrical power (W)
double m_fTireWidth
tire width
double m_fVelocity
wheel angular velocity (radians/second)
#define M_TAU
tau = 2 * pi
int m_nMotorIndex
motor controller unique motor index
uint_t m_uPulsesPerRev
encoder pulses per motor revolution
motor 2 over current warning
double m_fPosition
wheel angular position (radians)
void getTireDimParams(const std::string &strName, double &fTireRadius, double &fTireWidth) const
Get tire dimensions tune parameters.
Laelaps real-time "database".
int m_nSpeed
raw speed (qpps)
Top-level package include file.
static const double ParamAmpMax
maximum amps