 |
RSeries astromech firmware
|
|
Go to the documentation of this file.
22 #ifndef ROBOTEQCONTROLLER_H
23 #define ROBOTEQCONTROLLER_H
84 uint32_t startTime = millis();
87 fSerial->write(kROBOTEQ_QUERY_CHAR);
90 while (millis() - startTime < (uint32_t)fTimeout)
93 if (fSerial->available() > 0)
95 inByte = m_Serial->read();
96 if (inByte == kROBOTEQ_ACK_CHAR)
112 char command[kROBOTEQ_COMMAND_BUFFER_SIZE];
125 char command[kROBOTEQ_COMMAND_BUFFER_SIZE];
139 memset(buf, NULL, bufSize);
140 return sendQuery(
"?FID\r", (uint8_t*)buf, 100);
153 char buffer[kROBOTEQ_BUFFER_SIZE];
157 if ((
res = sendQuery(
"?BA\r", (uint8_t*)
buffer, kROBOTEQ_BUFFER_SIZE)) < 0)
163 if (sscanf((
char*)
buffer,
"BA=%i:%i", &ch1, &ch2) < 2) {
182 char command[kROBOTEQ_COMMAND_BUFFER_SIZE];
190 if ((
res = this->sendQuery(
command, (uint8_t*)
buffer, kROBOTEQ_BUFFER_SIZE)) < 0)
212 uint8_t
buffer[kROBOTEQ_BUFFER_SIZE];
214 memset(
buffer, NULL, kROBOTEQ_BUFFER_SIZE);
216 if ((
res = this->sendQuery(
"?V 2\r", (uint8_t*)
buffer, kROBOTEQ_BUFFER_SIZE)) < 0)
221 if (sscanf((
char*)
buffer,
"V=%i", &voltage) != 1)
235 uint8_t
buffer[kROBOTEQ_BUFFER_SIZE];
237 memset(
buffer, NULL, kROBOTEQ_BUFFER_SIZE);
239 if ((
res = this->sendQuery(
"?V 1\r", (uint8_t*)
buffer, kROBOTEQ_BUFFER_SIZE)) < 0)
244 if (sscanf((
char*)
buffer,
"V=%i", &voltage) != 1)
260 char command[kROBOTEQ_COMMAND_BUFFER_SIZE];
261 char buffer[kROBOTEQ_BUFFER_SIZE];
268 if ((
res = this->sendQuery(
"?BA\r", (uint8_t*)
buffer, kROBOTEQ_BUFFER_SIZE)) < 0)
274 if (sscanf((
char*)
buffer,
"M=%i", &p) < 1) {
289 uint8_t
buffer[kROBOTEQ_BUFFER_SIZE];
290 memset(
buffer, NULL, kROBOTEQ_BUFFER_SIZE);
292 if ((
res = this->sendQuery(
"?FF\r", (uint8_t*)
buffer, kROBOTEQ_BUFFER_SIZE)) < 0)
297 if (sscanf((
char*)
buffer,
"FF=%i", &fault) < 1)
309 uint8_t
buffer[kROBOTEQ_BUFFER_SIZE];
311 memset(
buffer, NULL, kROBOTEQ_BUFFER_SIZE);
313 if ((
res = this->sendQuery(
"?FS\r", (uint8_t*)
buffer, kROBOTEQ_BUFFER_SIZE)) < 0)
318 if (sscanf((
char*)
buffer,
"FS=%i", &status) < 1)
334 char command[kROBOTEQ_COMMAND_BUFFER_SIZE];
335 char buffer[kROBOTEQ_BUFFER_SIZE];
342 if ((
res = this->sendQuery(
command, (uint8_t*)
buffer, kROBOTEQ_BUFFER_SIZE)) < 0)
348 if (sscanf((
char*)
buffer,
"S=%i", &speed) < 1) {
364 char command[kROBOTEQ_COMMAND_BUFFER_SIZE];
379 char command[kROBOTEQ_COMMAND_BUFFER_SIZE];
391 char command[kROBOTEQ_COMMAND_BUFFER_SIZE];
403 char command[kROBOTEQ_COMMAND_BUFFER_SIZE];
405 return this->sendCommand(
command);
419 kROBOTEQ_DEFAULT_TIMEOUT = 1000,
420 kROBOTEQ_BUFFER_SIZE = 64,
421 kROBOTEQ_COMMAND_BUFFER_SIZE = 20,
423 kROBOTEQ_QUERY_CHAR = 0x05,
424 kROBOTEQ_ACK_CHAR = 0x06
427 inline int sendQuery(
const char *query, uint8_t *buf,
size_t bufSize)
429 return sendQuery(query, strlen(query), buf, bufSize);
432 int sendQuery(
const char *query,
size_t querySize, uint8_t *buf,
size_t bufSize)
438 fSerial->write((uint8_t*)query, querySize);
442 int res = readResponse(buf, bufSize);
446 inline int sendCommand(
const char *
command)
451 int sendCommand(
const char *
command,
size_t commandSize)
457 fSerial->write((uint8_t*)
command, commandSize);
460 uint8_t
buffer[kROBOTEQ_BUFFER_SIZE];
464 if ((
res = this->readResponse((uint8_t*)
buffer, kROBOTEQ_BUFFER_SIZE)) < 0)
471 if (strncmp((
char*)
buffer,
"+", 1) == 0)
476 int readResponse(uint8_t *buf,
size_t bufSize)
480 uint32_t startTime = millis();
481 while (millis() - startTime < fTimeout)
483 if (m_Serial->available() > 0)
485 inByte = m_Serial->read();
486 buf[index++] = inByte;
487 if (index > bufferSize)
502 static char* chomp(
char* s)
504 int end = strlen(s) - 1;
505 if (end >= 0 && (s[end] ==
'\n' || s[end] ==
'\r'))
@ kROBOTEQ_SCRIPT_RUN
Definition: RoboteQController.h:61
RoboteQController(Stream *serial)
Constructor.
Definition: RoboteQController.h:67
@ kROBOTEQ_FAULT_OVERVOLTAGE
Definition: RoboteQController.h:47
@ kROBOTEQ_FAULT_MOSFET
Definition: RoboteQController.h:52
char buffer[kROBOTEQ_BUFFER_SIZE]
Definition: RoboteQController.h:183
int queryEncoderSpeed(uint8_t ch)
Query encoder speed in RPM.
Definition: RoboteQController.h:329
int commandEmergencyStop(void)
Send emergency stop command (!EX) note: you have to reset the controller after this sending command.
Definition: RoboteQController.h:123
int queryStatusFlag(void)
Query status flags.
Definition: RoboteQController.h:305
Communicate with a Roboteq controller.
Definition: RoboteQController.h:34
int saveConfiguration(void)
Save controller configuration.
Definition: RoboteQController.h:401
int queryBatteryAmps(void)
Query battery amps.
Definition: RoboteQController.h:148
@ kROBOTEQ_FAULT_SHORT
Definition: RoboteQController.h:49
@ kROBOTEQ_STATUS_ANALOG
Definition: RoboteQController.h:57
int queryMotorVoltage(void)
Query motor voltage.
Definition: RoboteQController.h:231
@ kROBOTEQ_FAULT_OVERHEAT
Definition: RoboteQController.h:46
@ kROBOTEQ_BAD_COMMAND
Definition: RoboteQController.h:42
void setTimeout(uint16_t timeout)
Set timeout.
Definition: RoboteQController.h:411
@ kROBOTEQ_OK
Definition: RoboteQController.h:39
int res
Definition: RoboteQController.h:184
int queryBatteryVoltage(void)
Query battery voltage.
Definition: RoboteQController.h:208
int loadConfiguration(void)
Load controller configuration.
Definition: RoboteQController.h:389
@ kROBOTEQ_ERROR
Definition: RoboteQController.h:41
int setEncoderPulsePerRotation(uint8_t ch, uint16_t ppr)
Set encoder pulse per rotation.
Definition: RoboteQController.h:362
@ kROBOTEQ_FAULT_SCRIPT
Definition: RoboteQController.h:51
return amps
Definition: RoboteQController.h:200
int isConnected(void)
Check if controller is connected.
Definition: RoboteQController.h:78
@ kROBOTEQ_TIMEOUT
Definition: RoboteQController.h:40
@ kROBOTEQ_FAULT_CONFIG
Definition: RoboteQController.h:53
@ kROBOTEQ_BAD_RESPONSE
Definition: RoboteQController.h:43
@ kROBOTEQ_STATUS_SERIAL
Definition: RoboteQController.h:55
@ kROBOTEQ_STATUS_STALL
Definition: RoboteQController.h:59
int commandMotorPower(uint8_t ch, int16_t p)
Send motor power command (!G)
Definition: RoboteQController.h:110
@ kROBOTEQ_FAULT_ESTOP
Definition: RoboteQController.h:50
@ kROBOTEQ_FAULT_UNDERVOLTAGE
Definition: RoboteQController.h:48
int queryFirmware(char *buf, size_t bufSize)
Query controller firmware.
Definition: RoboteQController.h:135
sprintf(command, "?BA %i\r", ch)
int queryFaultFlag(void)
Query fault flags.
Definition: RoboteQController.h:284
@ kROBOTEQ_BUFFER_OVER
Definition: RoboteQController.h:44
@ kROBOTEQ_STATUS_PULSE
Definition: RoboteQController.h:56
char command[kROBOTEQ_COMMAND_BUFFER_SIZE]
Definition: RoboteQController.h:178
int queryMotorPower(uint8_t ch)
Query the motor power command.
Definition: RoboteQController.h:255
@ kROBOTEQ_STATUS_POWER_OFF
Definition: RoboteQController.h:58
int setMotorAmpLimit(uint8_t ch, uint16_t a)
Set motor amp limit.
Definition: RoboteQController.h:377
@ kROBOTEQ_STATUS_LIMIT
Definition: RoboteQController.h:60