In my wrapper class I have:
// (ROSArdbase is an abstract class. The idea is to have separate children classes for each type of motor controller.)
class ROSArdRoboclaw: public ROSArdBase {
public:
int rcAddress; // address of the controller.
RoboClaw *RCmc; // instance of the RoboClaw controller object.
public:
ROSArdRoboclaw(RoboClaw *mc, int address, long baud) {
this->RCmc = mc; // instance of RoboClaw class
this->rcAddress = address; // address of RoboClaw (allow use of multiple controllers)
this->cbBaud = baud; // set controller board baud rate. (Between Arduino and RoboClaw)
}
bool getPIDfromRC(VPID *p, int motor); // retrieve settings actually on RoboClaw
...snip...
In main sketch I first initialize an instance of the RoboClaw controller with:
#include "ROSArdRoboclaw.h"
#include "BMSerial.h"
#include "RoboClaw.h"
// set up roboclaw object on RX 10, TX 11 with 10ms of timeout (between Arduino and RC)
RoboClaw mc(10,11,10000);
// and then pass this object to my wrapper class:
ROSArdRoboclaw bot(&mc,0x80,38400);
Everything 'works' Commands that I execute through the wrapper class are passed to the motor controller and executed as expected. For example the getPIDfromRC method correctly returns values into the VPID structure, as well as all other methods that I've wrapped.
What's not working is that boolean values from the various base RoboClaw methods are not 'rippling' up.
For example, one of my wrapper methods is:
bool ROSArdRoboclaw::getPIDfromRC(VPID *p, int motor) {
bool valid;
if (motor == LEFT) {
// valid should be 1, but is always 0, even though I've confirmed that this
// command is executing and reading values correctly !!!
valid = this->RCmc->ReadM1VelocityPID(this->rcAddress, p->P,p->I,p->D,p->qpps);
} else if (motor == RIGHT) {
valid = this->RCmc->ReadM2VelocityPID(this->rcAddress, p->P,p->I,p->D,p->qpps);
} else {
return false;
}
return valid;
}
but even though ReadM1VelocityPID is executed successfully on the motor controller, the boolean 'true' value it's returning is not making its way into 'valid'
In the RoboClaw.h we see that it should be returning a 'true' upon success:
.h
bool ReadM1VelocityPID(uint8_t address,float &Kp_fp,float &Ki_fp,float &Kd_fp,uint32_t &qpps);
bool ReadM2VelocityPID(uint8_t address,float &Kp_fp,float &Ki_fp,float &Kd_fp,uint32_t &qpps);
.cpp
bool RoboClaw::ReadM1VelocityPID(uint8_t address,float &Kp_fp,float &Ki_fp,float &Kd_fp,uint32_t &qpps){
uint32_t Kp,Ki,Kd;
bool valid = read_n(4,address,READM1PID,&Kp,&Ki,&Kd,&qpps);
Kp_fp = ((float)Kp)/65536;
Ki_fp = ((float)Ki)/65536;
Kd_fp = ((float)Kd)/65536;
return valid;
}
I've confirmed that if I just use the motor controller instance 'mc' established at the beginning of the sketch rather than through my wrapper class, it ~does~ return the correct BOOL value upon success.
For example:
valid = mc.ReadM1VelocityPID(0x80,test2.P,test2.I,test2.D,test2.qpps);
results in valid being set to '1' which is the expected result as well as returning the same values for the PID as my wrapper method does.
Question. Why is the boolean value from the RoboClaw method not making it's way up through my wrapper object???
I'd like to be able to test for valid execution of commands just as I can if accessing the motor controller object directly.