Wrapping advanced PID library *variable &address problem

Hello, beginner PID does not meet the needs for my project (no limits, hardly suitable for integrating processes etc.)
I want to wrap Arduino PID library into XOD,
but I keep having errors I think originating from the way it requires linking addresses instead of normal values
Library says:
PID(double*, double*, double*,double, double, double, int, int);
Arduino example:
PID myPID(&Input, &Output, &Setpoint,2,5,1,P_ON_M, DIRECT);
one of many my unsuccessful attempts to wrap it up:

// Tell XOD where it could download the library and its dependencies:
#pragma XOD require "https://github.com/br3ttb/Arduino-PID-Library"

// Include C++ library:
#include <PID_v1.h>

node {
    meta {
        // Define our custom type as a pointer on the class instance.
        using Type = PID*;

    //PID myPID(&Input, &Output, &Setpoint,2,5,1,P_ON_M, DIRECT);
    PID aPID = PID(input_PV,output_OUT,input_SP,input_Kp,input_Ki,input_Kd,input_POM,input_DIR);

    void evaluate(Context ctx) {

        emitValue<output_OUT>(ctx, &aPID);

Also tried &input_PV and *input_PV but since I’m basically guessing no wonder it does not work.
Tried learning more, but could not find neither in depth explanations nor similar examples.
can you suggest a solution or an example?

A big part of your problem is that input_PV, output_OUT, etc. are not just “automagically” variables…you have to create them. I assume you are trying to get these values from pins on your node, so you would need to use getValue. Possible example (assuming input pins Input, Output, SP, parity, etc.):

    auto input = getValue<input_Input>(ctx);
    auto output = getValue<input_output>(ctx);
    auto SP = getValue<input_SP>(ctx);
    auto parity = getValue<input_parity>(ctx);
    [additional code here]
    PID aPID = PID(&input, &output, &SP, parity, [additional params]);

You might have to explicitly define variable types instead of using auto; especially since you are passing pointer to them to existing code expecting specific types.

I’ve adapted the XOD PID node to clip and control the ID part sensibly. It appears to be giving the expected result.

pid-control-clip.xodball (26.8 KB)

It applies a defer inside the node, and checks if in-bounds… Then passes the UPD through a GATE on the Integration; allowing Derivative update gives better response. The output is then clipped.

The XODBALL file compares the two PID methods

And works as expected when the value changes


Interesting, the defer has to be where it is… if you try to move it after the CLIP, then it does not work.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.