Hi guys, I copied this code and put it on Arduino, but it gives me this error:
C:\Users\Dario\AppData\Local\Temp\arduino_modified_sketch_255182\sketch_jul28a.ino:18:43: warning: invalid conversion from ‘void (*)()’ to 'void (*)(byte) {aka void (*)(unsigned char)}’ [-fpermissive]
PciListenerImp listenerA(encoder.pinA, doA);
In file included from C:\Users\Dario\AppData\Local\Temp\arduino_modified_sketch_255182\sketch_jul28a.ino:4:0:
C:\Users\Dario\Documents\Arduino\libraries\PciManager-2.1.4\src/PciListenerImp.h:45:5: note: initializing argument 2 of ‘PciListenerImp::PciListenerImp(byte, void (*)(byte), bool)’
PciListenerImp(byte pin, void (*callback)(byte changeKind), bool pullUp = false);
^~~~~~~~~~~~~~
C:\Users\Dario\AppData\Local\Temp\arduino_modified_sketch_255182\sketch_jul28a.ino:19:43: warning: invalid conversion from ‘void (*)()’ to 'void (*)(byte) {aka void (*)(unsigned char)}’ [-fpermissive]
PciListenerImp listenerB(encoder.pinB, doB);
^
In file included from C:\Users\Dario\AppData\Local\Temp\arduino_modified_sketch_255182\sketch_jul28a.ino:4:0:
C:\Users\Dario\Documents\Arduino\libraries\PciManager-2.1.4\src/PciListenerImp.h:45:5: note: initializing argument 2 of ‘PciListenerImp::PciListenerImp(byte, void (*)(byte), bool)’
PciListenerImp(byte pin, void (*callback)(byte changeKind), bool pullUp = false);
^~~~~~~~~~~~~~
C:\Users\Dario\AppData\Local\Temp\arduino_modified_sketch_255182\sketch_jul28a.ino: In function ‘void setup()’:
sketch_jul28a:72:20: error: ‘doTarget’ was not declared in this scope
command.add(‘T’, doTarget, “target velocity”);
^~~~~~~~
C:\Users\Dario\AppData\Local\Temp\arduino_modified_sketch_255182\sketch_jul28a.ino:72:20: note: suggested alternative: ‘onTarget’
command.add(‘T’, doTarget, “target velocity”);
^~~~~~~~
onTarget
exit status 1
‘doTarget’ was not declared in this scope
I am using the code under the “Position Control Example” page but i dont understand the error, I installed also the last version of SimpleFoc Library. Thanks for help
Hey @Patrizio_Zaccagnini,
The issue is related to the PCIManager
library, did you install it?
Which microcontroller are you using?
This library provides a way to use software interrupts if your board does not have any more the hardware interrupt pins available. This library is only available for arduino uno and other atmega328/atmega2560 chips.
If you are using the esp32/teensy/stm32… you can just comment out the code involving the PCIManager
.
Let me know if you still have some questions.
Yes, I installed it. But it’s not a problem of this library I think, because the code of that page doesn’t include it.
This is the code:
#include <SimpleFOC.h>
// init BLDC motor
BLDCMotor motor = BLDCMotor( 11 );
// init driver
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 10, 11, 8);
// init encoder
Encoder encoder = Encoder(2, 3, 2048);
// channel A and B callbacks
void doA(){encoder.handleA();}
void doB(){encoder.handleB();}
// angle set point variable
float target_angle = 0;
// commander interface
Commander command = Commander(Serial);
void onTarget(char* cmd){ command.scalar(&target_angle, cmd); }
void setup() {
// initialize encoder hardware
encoder.init();
// hardware interrupt enable
encoder.enableInterrupts(doA, doB);
// link the motor to the sensor
motor.linkSensor(&encoder);
// power supply voltage
// default 12V
driver.voltage_power_supply = 12;
driver.init();
// link the motor to the driver
motor.linkDriver(&driver);
// set control loop to be used
motor.controller = MotionControlType::angle;
// controller configuration based on the control type
// velocity PI controller parameters
// default P=0.5 I = 10
motor.PID_velocity.P = 0.2;
motor.PID_velocity.I = 20;
// jerk control using voltage voltage ramp
// default value is 300 volts per sec ~ 0.3V per millisecond
motor.PID_velocity.output_ramp = 1000;
//default voltage_power_supply
motor.voltage_limit = 6;
// velocity low pass filtering
// default 5ms - try different values to see what is the best.
// the lower the less filtered
motor.LPF_velocity.Tf = 0.01;
// angle P controller
// default P=20
motor.P_angle.P = 20;
// maximal velocity of the position control
// default 20
motor.velocity_limit = 4;
// initialize motor
motor.init();
// align encoder and start FOC
motor.initFOC();
// add target command T
command.add('T', doTarget, "target angle");
// monitoring port
Serial.begin(115200);
Serial.println("Motor ready.");
Serial.println("Set the target angle using serial terminal:");
_delay(1000);
}
void loop() {
// iterative FOC function
motor.loopFOC();
// function calculating the outer position loop and setting the target position
motor.move(target_angle);
}
I'm still trying but nothing...
Hey Patrizio,
It doesn’t look like you defined doTarget
. Did you mean to use onTarget
instead?