54 #include <sys/types.h> 60 #include "rnr/rnrconfig.h" 181 CmdBufDriveQAccel2Dist = 51,
469 virtual void select(
int fd, byte_t addrSel);
522 virtual int open(std::string &strDevName,
538 virtual int flushInput();
547 return m_fd >= 0?
true:
false;
557 m_bDbgEnable = bEnDis;
590 virtual int execCmd(byte_t cmd[],
size_t lenCmd);
603 virtual int execCmdWithAckRsp(byte_t cmd[],
size_t lenCmd,
621 virtual int execCmdWithDataRsp(byte_t cmd[],
size_t lenCmd,
622 byte_t rsp[],
size_t lenRsp,
637 virtual int sendCmd(byte_t cmd[],
size_t lenCmd,
649 virtual int recvDataRsp(byte_t rsp[],
size_t lenRsp);
657 virtual int recvAck();
669 int pack16(uint_t val, byte_t buf[]);
681 int unpack16(byte_t buf[], uint_t &val);
695 return pack16((uint_t)val, buf);
708 int unpack16(byte_t buf[],
int &val);
720 int pack32(uint_t val, byte_t buf[]);
732 int unpack32(byte_t buf[], uint_t &val);
746 return pack32((uint_t)val, buf);
759 int unpack32(byte_t buf[],
int &val);
773 virtual byte_t checksum(byte_t buf[],
size_t lenBuf,
bool bAck=
false);
784 virtual uint_t crc16(uint_t crc, byte_t buf[],
size_t lenBuf);
819 const byte_t address=AddrDft,
820 const std::string &strNameId=
"RoboClaw");
840 virtual bool probe(byte_t address);
864 return m_comm.isOpen();
907 m_strNameId = strNameId;
923 if( isValidMotor(motor) )
925 return m_nMotorDir[motor];
929 return MotorDirNormal;
945 if( isValidMotor(motor) )
947 m_nMotorDir[motor] = motorDir == MotorDirReverse? MotorDirReverse:
959 void getMainBattCutoffRange(
double &minmin,
double &maxmax)
const;
968 void getLogicCutoffRange(
double &minmin,
double &maxmax)
const;
984 virtual int cmdReadFwVersion(std::string &strFwVer);
995 virtual int cmdReadMainBattVoltage(
double &volts);
1008 virtual int cmdReadMainBattCutoffs(
double &min,
double &max);
1026 virtual int cmdSetMainBattCutoffs(
const double min,
const double max);
1038 virtual int cmdReadLogicVoltage(
double &volts);
1052 virtual int cmdReadLogicCutoffs(
double &min,
double &max);
1072 virtual int cmdSetLogicCutoffs(
const double min,
const double max);
1087 virtual int cmdReadVelocityPidConst(
int motor,
1109 virtual int cmdSetVelocityPidConst(
int motor,
1125 virtual int cmdReadMotorCurrentDraw(
double &s1,
double &s2);
1137 virtual int cmdReadMotorMaxCurrentLimit(
int motor,
double &maxAmps);
1149 virtual int cmdSetMotorMaxCurrentLimit(
int motor,
const double maxAmps);
1160 virtual int cmdReadBoardTemperature(
double &temp);
1171 virtual int cmdReadStatus(uint_t &status);
1183 virtual int cmdReadCmdBufLengths(uint_t &len1, uint_t &len2);
1195 virtual int cmdReadEncoderMode(byte_t &mode1, byte_t &mode2);
1210 virtual int cmdSetEncoderMode(
int motor, byte_t mode);
1225 virtual int cmdSetEncoderMode2(byte_t mode1, byte_t mode2);
1234 virtual int cmdResetQEncoders();
1247 virtual int cmdReadQEncoder(
int motor, s64_t &encoder);
1263 virtual int cmdDutyDrive2(
double duty1,
double duty2);
1275 virtual int cmdReadQSpeed(
int motor, s32_t &speed);
1290 virtual int cmdQDrive(
int motor, s32_t speed);
1306 virtual int cmdQDrive2(s32_t speed1, s32_t speed2);
1323 virtual int cmdQDriveWithAccel(
int motor, s32_t speed, u32_t accel);
1342 virtual int cmdQDriveWithAccel(s32_t speed1, u32_t accel1,
1343 s32_t speed2, u32_t accel2);
1367 virtual int cmdQDriveForDist(
int motor, s32_t speed, u32_t dist,
1394 virtual int cmdQDriveForDist(s32_t speed1, u32_t dist1,
1395 s32_t speed2, u32_t dist2,
1422 virtual int cmdQDriveWithAccelForDist(
int motor,
1455 virtual int cmdQDriveWithAccelForDist(s32_t speed1,
1488 virtual int cmdQDriveWithProfileToPos(
int motor,
1524 virtual int cmdQDriveWithProfileToPos(s32_t speed1,
1545 return cmdQDrive2(0, 0);
1562 virtual int cmdSDrive(
int motor,
int speed);
1581 virtual int cmdSDrive2(
int speed1,
int speed2);
1594 virtual int cmdStop(
int motor);
1610 virtual int cmdStopWithDecel(
int motor, u32_t decel);
1621 virtual int cmdStop();
1636 virtual int cmdStopWithDecel(u32_t decel);
1645 virtual int cmdEStop();
1654 virtual int cmdWriteSettingsToEEPROM();
1660 int m_nMotorDir[NumMotors];
1661 s64_t m_nEncPrev[NumMotors];
1662 s64_t m_nEncoder[NumMotors];
1673 return (motor >= Motor1) && (motor < NumMotors);
1697 static inline int cap(
int a,
int min,
int max)
1699 return a<min? min: a>max? max: a;
1711 static inline double fcap(
double a,
double min,
double max)
1713 return a<min? min: a>max? max: a;
1724 #endif // _ROBO_CLAW_H static const int MotorDirUnknown
unknown
std::string m_strNameId
controller name identifier
static const int ParamDutyCycleStop
0% duty cycle
logic battery under volt error
drive motros at qpps with 2 accel vals
static const byte_t ParamVoltMaxMainMin
0 == 0 volts
buffered drive motor 1 to dist at qpps
RoboClaw 2 motor controller class.
static const long ParamVelPidDDft
vel derivative const
uint_t m_uCrcRsp
last received response's CRC
static const byte_t ParamTurn7MaxRight
full turn right
static const double ParamAmpMin
minimum amps
message includes a 16-bit CRC
static const byte_t ParamSpeed7MaxBwd
minimum absolute speed
read motor 2 velocity PID constants
buffered drive motor 2 to dist at qpps with accel.
static const int MotorSpeedMaxForward
full forward
static const double ParamVotlMinMainDft
default on reset
ParamEncStatus
Encoder status on read.
static const int FieldPosCmd
command id position
static const int USBBaud1Mbps
1Mbps USB typical baudrate
int m_nBaudRate
serial baud rate
read current board status
virtual void enableDbg(bool bEnDis)
Test if connection is open.
read motor 1 speed (qpps)
virtual void setMotorDir(int motor, int motorDir)
set the direction of motor rotation.
static const int CmdHdrLen
cmd header length [address,cmdid]
static const long ParamPosPidPDft
pos proportional const
drive motor 1 at quad. pulses/second
message does not include a 16-bit CRC
static const uint_t RspTimeout
response timeout (usec)
static const byte_t ParamVoltMinMainMin
0 == 6 volts
read motor 2 position PID constants
static const double ParamVoltMinS
(V - Off) * S = value
reset encoder (quadrature )counters
static const long ParamPosPidMinPos
min position
read board second temperature
drive motor 1 at duty cycle (no quad.)
bool m_bDbgEnable
do [not] enable debugging
read motor 1 position PID constants
static const byte_t ParamEncModeRCAnalogEn
RC/analog enable.
static const byte_t AddrMin
minimum controller address
static const byte_t ParamSpeedMin
minimum absolute speed
drive motor 1 at quad. pps with accel.
set motor 1 position PID constants
static const byte_t ParamEncModeRCAnalogBit
RC/analog bit.
drive motors with signed qpps, accel, deccel and position
virtual bool isValidMotor(int motor) const
Test if motor index is a valid index.
temp2 out-of-range warning
static double fcap(double a, double min, double max)
Cap FPN value within limits [min, max].
drive motors at quad. pps with accel.
static const double ParamAmpScale
sensed_value * S = A
static const byte_t AddrMax
maximum controller address
static const byte_t ParamVoltMinMainMax
120 == 30 volts
static const int RspMaxBufLen
maximum response length (bytes)
set main battery minimum voltage
set logic battery maximum voltage
set main battery voltage cutoffs
set encoder register 2 (quadrature)
RoboClawChipSelect()
Default constructor.
static const long ParamPosPidIDft
pos integrative const
static const long ParamPosPidMaxPos
max position
buffered drive motor 2 to dist at qpps
ParamStatus
Board status bits.
static const byte_t ParamCmdBufQueue
queue command
buffered drive motors to dist at qpps w/ 2 accel
static const int MotorDirReverse
reverse (forward=backward, etc)
static const int ParamDutyCycleMin
-100% duty cycle
static const int MotorSpeedStop
stop
set main battery maximum voltage
static const byte_t ParamEncModeAbs
absolute encoder
int m_fd
opened file descriptor
drive motor 2 with signed qpps, accel, deccel and position
static const byte_t ParamCmdBufExec
last command is executing
static const long ParamPosPidDDft
pos derivative const
static const double ParamVoltMinLogicOff
V @ 0 value.
static const int SerBaud115200
115200 serial baudrate
static const byte_t ParamVoltMinLogicMax
120 == 30 volts
drive motors to turn left
static const int SerBaud460800
460800 serial baudrate
static const byte_t ParamEncModeRCAnalogDis
RC/analog disable.
set motor 2 velocity PID constants
read motor 1 maximum current limit
set motor 1 maximum current limit
static const byte_t ParamSpeed7MaxFwd
maximum absolute speed
int pack16(int val, byte_t buf[])
Pack 16-bit signed value into buffer.
virtual void select(int fd, byte_t addrSel)
Motor controller select function.
static const int NumMotors
number of motors/controller
std::string getNameId() const
Get class instance name identifier.
static const double ParamVoltLogicMin
minimum logic voltage
temperature out-of-range error
RoboClaw motor controller chip select class.
static const double ParamAmpMinSane
minimum amps for operation
std::string m_strDevName
serial device name
static const byte_t ParamTurn7MaxLeft
full turn left
static const byte_t ParamVoltMaxLogicMin
30 == 6 volts
RoboClawComm & m_comm
bound communication object
byte_t m_address
assigned controller address
RoboClawChipSelect * m_pChipSelect
motor ctlr select object
virtual int cmdQStop()
Stop both motors.
static const long ParamPosPidMaxIDft
max I windup
main battery over voltage error
static const byte_t ParamVoltMaxMainMax
154 == 30 volts
static const byte_t ParamStop7
all stop
static const int MotorDirNormal
normal
read motor 1 speed (pulses/125th sec)
set motor 1 velocity PID constants
static const int FieldPosAddr
controller address position
static const int SerBaud230400
230400 serial baudrate
temp out-of-range warning
static const double ParamVoltMainMin
min main battery voltage
static const long ParamVelPidQppsDft
speed of encoder at max
static const byte_t ParamCmdBufEmpty
buffer is empty
static const uint_t CmdTimeout
command timeout (usec)
static const double ParamVoltSensedS
sensed_value * S = V
static int cap(int a, int min, int max)
Cap value within limits [min, max].
static const size_t ParamVerLenMin
version minimum length.
drive motors to turn R/L (7-bit)
read encoder mode for both motors
read motor 2 speed (pulses/125th sec)
static const byte_t ParamNoTurn7
no turn
main battery over volt warning
set motor 2 position PID constants
virtual ~RoboClawChipSelect()
Destructor.
static const long ParamPosPidDeadzoneDft
deadzone
byte_t m_addrLast
last selected motor controller, id'd by address
static const byte_t CheckSumMask
checksum mask
static const long long ParamEncQuadMax
quadrature encoder max
static const byte_t ParamSpeedMax
maximum absolute speed
bool isOpen() const
Test if connection is open.
buffered drive motors to dist at qpps with accel.
drive motors at quad. pulses/second
static const int ParamDutyCycleMax
100% duty cycle
drive motors foward/back (7-bit)
read motor 2 speed (qpps)
static const long ParamVelPidPDft
vel proportional const
read motors bufferd command length
static const byte_t ParamStop
stop
static const long ParamVelPidCvt
vel const conversion
read main battery voltage
message is variable length
RoboClawComm & getComm()
Get RoboClaw's bound communication object.
static int abs(int a)
Integer absolute value.
static const int SerBaud19200
19200 serial baudrate
static const double ParamVoltMaxS
V * S = value.
response includes a CRC, ignore (fw work-around bug)
drive motor 1 with signed qpps, accel, deccel and position
static const byte_t ParamTurnMin
min absolute turn speed
static const long long ParamEncQuadMin
quadrature encoder min
main battery under volt warning
int pack32(int val, byte_t buf[])
Pack 32-bit signed value into buffer.
read main battery cutoff settings
static const int SerBaud9600
9600 serial baudrate
set logic battery minimum voltage
read logic voltage cutoff settings
static const double ParamVoltMax
maximum voltage
logic battery over volt error
static const byte_t RspAck
ack response to write commands
motor 1 over current warning
set encoder register 1 (quadrature)
static const byte_t ParamVoltMinLogicMin
0 == 6 volts
byte_t getAddress() const
Get the controller address associated with this class instance.
virtual byte_t getMotorDir(int motor) const
Get the direction of motor rotation.
buffered drive motor 1 to dist at qpps with accel.
uint_t getLastCmdCrc()
Get last sent command's calculated 16-bit CRC.
uint_t m_uCrcCmd
last sent command's CRC
buffered drive motors to dist at qpps
static const size_t ParamVerLen
version string length.
static const int SerBaud38400
38400 serial baudrate
static const byte_t ParamTurnMax
max absolute turn speed
static const byte_t AddrDft
default controller address
drive motor 2 at quad. pps with accel.
drive motor 1 forward/back (7-bit)
static const byte_t ParamEncModeQuad
quadrature encoder
static const byte_t ParamCmdBufSize
cmd buffer size (num q'd)
RoboClaw communication class.
drive motor 2 at duty cycle (no quad.)
static const double ParamVoltScale
10/th of a volt
drive motor 2 foward/back (7-bit)
set logic voltage cutoffs
static const byte_t ParamEncModeQuadAbsBit
quad/absolute bit
static const byte_t ParamCmdBufPreempt
preempt all buffered cmds
drive motor 2 at quad. pulses/second
static const int SerBaud2400
2400 serial baudrate
void setNameId(const std::string &strNameId)
Set class instance name identifier.
MsgFmt
Command and response message formats.
virtual bool isOpen() const
Test if connection is open.
drive motors to turn right
motor 2 over current warning
temperature2 out-of-range error
quadrature encoder underflow
static const byte_t ParamNoTurn
no turn
static const long ParamVelPidIDft
vel integrative const
quadrature encoder overflow
uint_t getLastRspCrc()
Get last received response's appended 16-bit CRC.
drive motors at duty cycle (no quad.)
static const int CmdMaxBufLen
maximum command length (bytes)
static const double ParamVoltMinMainOff
V @ 0 value.
static const int Motor2
motor 2
static const int Motor1
motor 1
void setAddress(byte_t address)
Set class instance address.
static const int MotorSpeedMaxBackward
full reverse
static const double ParamTempScale
sensed_value * S = C
read motor 2 maximum current limit
static const byte_t ParamVoltMaxLogicMax
175 == 34 volts
read logic battery voltage
static const double ParamAmpMax
maximum amps
set motor 2 maximum current limit
static const byte_t AckReqBit
request ack to write commands