runger1101001 / Arduino-FOC-dcmotor

MIT License
3 stars 10 forks source link

More detailed examples can be found here: Link missing #3

Open ator1811 opened 1 year ago

ator1811 commented 1 year ago

Hi, I want to try this library. In the Readme a reference is made to more detailed examples, but the link to https://github.com/runger1101001/Arduino-FOC-dcmotor/blob/examples is missing.

Do you have some examples? E.g how is the motor object created? What libraries to include?

Thanks /A

runger1101001 commented 1 year ago

Hi, and thanks for asking! Yes, the link to the example is broken, sorry about this. I still have to commit the example to the repository.

This code is very very new, and not yet really tested... so I am sorry if you experience troubles. If you want to try it out, the basic code is probably something like this:

DCMotor motor = DCMotor();
DCDriver driver = DCDriver2PWM(1,2,3);
Sensor sensor = MagneticSensorAS5048A(10);

void setup() {
    sensor.init();
    driver.init();
    motor.linkSensor(&sensor);
    motor.linkDriver(&driver);
    motor.controller = MotionControlType::torque;
    motor.torque_controller = TorqueControlType::voltage;
    motor.init();
}

void loop() {
    motor.move(5); // 5 Volts
}

There are different DCDriver classes to choose from, depending on the type of your motor driver and the inputs it needs. And of course you have to adjust the pin numbers in this example to match the pins you're actually using...

If you decide to try it out, please let us know how it goes for you. If you prefer to wait until the code is a bit more tested and there are more examples, stay tuned, I hope to have time to do this during the next few weeks.

ator1811 commented 1 year ago

Thanks, I'll give it a go. What are the libraries to include? These?

#include <SimpleFOC.h>
#include <DCMotor.h>

I get a compile error: Compilation error: invalid cast to abstract class type 'DCMotor'

runger1101001 commented 1 year ago

Thanks for reporting... I will look into it!

runger1101001 commented 1 year ago

This was an incompatibility with SimpleFOC 2.2.3, I have updated the code so it compiles.

I have to stress that this code is untested, really, so far, so you may find more issues. Sorry for it! Over the next few weeks I will be testing it and adding some examples, so you may want to wait a little... or else if you wish to test it out, I am very grateful for any help!

ator1811 commented 1 year ago

Thanks for the effort. I updated the library, but still compilation errors. I can report them to you if you wish.

I can wait a couple of weeks when you are ready with the testing, so no hurry for me.

runger1101001 commented 1 year ago

So, I have fixed many bugs, and for me the code is now tested working with the following:

It is working well now. The code that is working for me is exactly this example: https://github.com/runger1101001/Arduino-FOC-dcmotor/blob/main/examples/dc-velocity/dc-velocity.ino

I have only tested on Arduino Nano so far. Please if you have time let me know which MCU type you are using, and I will check compilation on this MCU if I can.

runger1101001 commented 1 year ago

Oh, and the "link missing" problem is fixed now too.