B4R Question Wrap AutoPid double *input in Constructor

KiloBravo

Member
Licensed User
B4X:
// Constructor - takes pointer inputs for control variales, so they are updated automatically
    AutoPID(double *input, double *setpoint, double *output, double outputMin, double outputMax, double Kp, double Ki, double Kd);
 // Allows manual adjustment of gains

C-like:
AutoPID::AutoPID(double *input, double *setpoint, double *output, double outputMin, double outputMax,
                 double Kp, double Ki, double Kd) {
  _input = input;
  _setpoint = setpoint;
  _output = output;
  _outputMin = outputMin;
  _outputMax = outputMax;
  setGains(Kp, Ki, Kd);
  _timeStep = 1000;
}//AutoPID::AutoPID

Still having issues wrapping my first library.

Do I do something like (ArrayDouble* arrInput = CreateStackMemoryObject(Input)) like the example below for for the Pointers to Doubles for input, setpoint, and output in my B4R::Initialize, since I can't expose pointers to Doubles in B4R ? Those three variables are updated as the PID object runs in the background.

B4X:
void MqttClient::callback(char* topic, uint8_t* payload, unsigned int length) {
        const UInt cp = B4R::StackMemory::cp;
        B4RString* strTopic = CreateStackMemoryObject(B4RString);
        strTopic->data = topic;
        
        ArrayByte* arrPayload = CreateStackMemoryObject(ArrayByte);
        arrPayload->data = payload;
        arrPayload->length = length;
        
        instance->MessageArrivedSub(strTopic, arrPayload);
        B4R::StackMemory::cp = cp;
//
 
Top