Skip to content

Commit bd42747

Browse files
committed
added minimal example
1 parent 8d73cd6 commit bd42747

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <ArduinoFOC.h>
2+
3+
// This example gives you a minimal code needed to run the FOC algorithm
4+
// All the configuration is set to defualt values
5+
// motor.power_supply_voltage= 12V
6+
// motor.driver = DriverType::bipolar
7+
// encoder.pullup = Pullup::EXTERN
8+
// motor.PI_velocity.K = 1
9+
// motor.PI_velocity.Ti = 0.003
10+
11+
// BLDCMotor( phA, phB, phC, pole_pairs, enable)
12+
BLDCMotor motor = BLDCMotor(9, 10, 11, 11, 8);
13+
// Encoder(encA, encB , cpr, index)
14+
Encoder encoder = Encoder(2, 3, 32768, 4);
15+
16+
// interrupt ruotine intialisation
17+
void doA(){encoder.handleA();}
18+
void doB(){encoder.handleB();}
19+
20+
void setup() {
21+
// debugging port
22+
Serial.begin(115200);
23+
24+
// initialise encoder hardware
25+
encoder.init(doA, doB);
26+
// link the motor to the sensor
27+
motor.linkEncoder(&encoder);
28+
// intialise motor
29+
motor.init();
30+
// velocity control
31+
motor.controller = ControlType::velocity;
32+
// align encoder and start FOC
33+
motor.initFOC();
34+
35+
Serial.println("Motor ready.");
36+
delay(1000);
37+
}
38+
39+
// target velocity variable
40+
float target_velocity = 2;
41+
42+
void loop() {
43+
// foc loop
44+
motor.loopFOC();
45+
// control loop
46+
motor.move(target_velocity);
47+
motor_monitor();
48+
}

0 commit comments

Comments
 (0)