Sorry if this question been posted but I couldn't find the one that matches my issue. I couldn't pass my struct values from the main file to a class. Any ideas? I got this:
error: no matching function for call to 'ODriveArduino::SetParam(R_motor_params&)'
Main.cpp:
#include ODriveArduino.h
ODriveArduino odrive(Serial1);
struct L_motor_params{
int axis=1;
float vel_Gain= 2.5f/10000.0f ;
float pos_Gain= 40.0f;
float vel_Int_Gain= 0.0f/10000.0f;
};
struct R_motor_params{
int axis=0;
float vel_Gain= 2.75f/10000.0f ;
float pos_Gain= 40.0f;
float vel_Int_Gain= 0.0f/10000.0f;
};
void setup() {
struct R_motor_params M;
odrive.SetParam(M);
}
ODriveArduino.h:
class ODriveArduino {
private:
struct motor_Params{
int axis;
float vel_Gain;
float pos_Gain;
float vel_Int_Gain;
};
public:
ODriveArduino(Stream& serial);
// Commands
void SetParam(struct motor_Params M);
}
ODriveArduino.cpp:
#include "ODriveArduino.h"
template<class T> inline Print& operator <<(Print &obj, T arg) { obj.print(arg); return obj; }
template<> inline Print& operator <<(Print &obj, float arg) { obj.print(arg, 4); return obj; }
ODriveArduino::ODriveArduino(Stream& serial)
: serial_(serial) {}
void ODriveArduino::SetParam(struct motor_Params M){
Serial1 << "w axis" << M.axis << ".motor.config.pos_gain " << M.pos_Gain << '\n';
Serial1 << "w axis" << M.axis << ".motor.config.vel_gain " << M.vel_Gain << '\n';
Serial1 << "w axis" << M.axis << ".motor.config.vel_integrator_gain " << M.vel_Int_Gain << '\n';
}
motor_Params,R_motor_Params,L_motor_Params, but you want the L and R to be variables of typemotor_ParamsR_motor_ParamsandL_motor_Paramshave slightly different values. I want to pass them toSetParam. I figured, to do that, I need to have an identical struct in ODriveArduino.h so thatSetParamknows what to expect. Obviously that didn't work. I'm not sure what I'm missing.motor_params L_motor_params;creates a variable of typemotor_params1namedL_motor_params