simplefoc / Arduino-FOC

Arduino FOC for BLDC and Stepper motors - Arduino Based Field Oriented Control Algorithm Library
https://docs.simplefoc.com
MIT License
2.1k stars 537 forks source link

Error compiling for board Arduino Leonardo: a function-definition is not allowed here before '{' token #170

Closed akakikuumeri closed 2 years ago

akakikuumeri commented 2 years ago

Compiling the velocity_control.ino example and all other sketches I have tried, using v. 2.2.1, targeting Arduino Leonardo in Arduino IDE on Windows exit with the following errors:

C:\Users\*****\Documents\Arduino\libraries\Simple_FOC\src\drivers\hardware_specific\atmega32u4_mcu.cpp: In function 'int _configure6PWM(long int, float, int, int, int, int, int, int)':
C:\Users\*****\Documents\Arduino\libraries\Simple_FOC\src\drivers\hardware_specific\atmega32u4_mcu.cpp:151:1: error: a function-definition is not allowed here before '{' token
 {
 ^
C:\Users\*****\Documents\Arduino\libraries\Simple_FOC\src\drivers\hardware_specific\atmega32u4_mcu.cpp:166:151: error: a function-definition is not allowed here before '{' token
 void _writeDutyCycle6PWM(float dc_a,  float dc_b, float dc_c, float dead_zone, int pinA_h, int pinA_l, int pinB_h, int pinB_l, int pinC_h, int pinC_l){
                                                                                                                                                       ^
C:\Users\***\Documents\Arduino\libraries\Simple_FOC\src\drivers\hardware_specific\atmega32u4_mcu.cpp:170:1: error: expected '}' at end of input
 }
 ^
exit status 1
Error compiling for board Arduino Leonardo.

Further, I also get multiple warnings like

C:\Users\*****\Documents\Arduino\libraries\Simple_FOC\src/communication/Commander.h:210:68: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
     void target(FOCMotor* motor, char* user_cmd, char* separator = " ");

on both Leonardo but also on Arduino MEGA, but there they don't prevent me from compiling, so I am not sure if they are related to the error.

askuric commented 2 years ago

Hey @akakikuumeri, it seems like there is a forgotten bracket :/

In the file atmega32u4_mcu.h on the line 147.

https://github.com/simplefoc/Arduino-FOC/blob/47e1a7b42f7c0004006be674d9b988aa8a5b3083/src/drivers/hardware_specific/atmega32u4_mcu.cpp#L137

The code for the Leonardo is not much tested, please do not hesitate to post issues if you'll have ,more of them. Its going to help us improve our support!

Btw, the warning is ok, not a big deal. It will be removed in the next release.

akakikuumeri commented 2 years ago

Thanks a lot! I should've been able to fix that myself, but I'm only getting used to the project. Thank you for your help.

I'm trying to get an Arduino Pro Micro to work with some AS5600 sensors and a stepper motor. I'll post issues if I run into more.

askuric commented 2 years ago

Fixed in the dev branch, by richard few months ago. The bug will be removed in the next release v2.2.2