Skip to content

Commit 4101a6e

Browse files
author
askuric
committed
kv rating find examples
1 parent daaa3e1 commit 4101a6e

File tree

3 files changed

+304
-0
lines changed

3 files changed

+304
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/**
2+
*
3+
* Find KV rating for motor with encoder
4+
*
5+
* Motor KV rating is defiend as the increase of the motor velocity expressed in rotations per minute [rpm] per each 1 Volt int voltage control mode.
6+
*
7+
* This example will set your motor in the torque control mode using voltage and set 1 volt to the motor. By reading the velocity it will calculat the motors KV rating.
8+
* - To make this esimation more credible you can try increasing the target voltage (or decrease in some cases)
9+
* - The KV rating should be realatively static number - it should not change considerably with the increase in the voltage
10+
*
11+
*/
12+
#include <SimpleFOC.h>
13+
14+
15+
// BLDC motor & driver instance
16+
BLDCMotor motor = BLDCMotor(11);
17+
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
18+
// Stepper motor & driver instance
19+
//StepperMotor motor = StepperMotor(50);
20+
//StepperDriver4PWM driver = StepperDriver4PWM(9, 5, 10, 6, 8);
21+
22+
// encoder instance
23+
Encoder encoder = Encoder(2, 3, 8192);
24+
25+
// Interrupt routine intialisation
26+
// channel A and B callbacks
27+
void doA(){encoder.handleA();}
28+
void doB(){encoder.handleB();}
29+
30+
31+
// voltage set point variable
32+
float target_voltage = 1;
33+
34+
// instantiate the commander
35+
Commander command = Commander(Serial);
36+
void doTarget(char* cmd) { command.scalar(&target_voltage, cmd); }
37+
void calcKV(char* cmd) {
38+
// calculate the KV
39+
Serial.println(motor.shaft_velocity/motor.target*30.0f/_PI);
40+
41+
}
42+
43+
void setup() {
44+
45+
// initialize encoder sensor hardware
46+
sensor.init();
47+
sensor.enableInterrupts(doA, doB, doC);
48+
// link the motor to the sensor
49+
motor.linkSensor(&sensor);
50+
51+
// driver config
52+
// power supply voltage [V]
53+
driver.voltage_power_supply = 12;
54+
driver.init();
55+
// link driver
56+
motor.linkDriver(&driver);
57+
58+
// aligning voltage
59+
motor.voltage_sensor_align = 3;
60+
61+
// choose FOC modulation (optional)
62+
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
63+
64+
// set motion control loop to be used
65+
motor.controller = MotionControlType::torque;
66+
67+
// use monitoring with serial
68+
Serial.begin(115200);
69+
// comment out if not needed
70+
motor.useMonitoring(Serial);
71+
72+
// initialize motor
73+
motor.init();
74+
// align sensor and start FOC
75+
motor.initFOC();
76+
77+
// add target command T
78+
command.add('T', doTarget, "target voltage");
79+
command.add('K', calcKV, "calculate KV rating");
80+
81+
Serial.println(F("Motor ready."));
82+
Serial.println(F("Set the target voltage : - commnad T"));
83+
Serial.println(F("Calculate the motor KV : - command K"));
84+
_delay(1000);
85+
}
86+
87+
88+
void loop() {
89+
90+
// main FOC algorithm function
91+
// the faster you run this function the better
92+
// Arduino UNO loop ~1kHz
93+
// Bluepill loop ~10kHz
94+
motor.loopFOC();
95+
96+
// Motion control function
97+
// velocity, position or voltage (defined in motor.controller)
98+
// this function can be run at much lower frequency than loopFOC() function
99+
// You can also use motor.move() and set the motor.target in the code
100+
motor.move(target_voltage);
101+
102+
// user communication
103+
command.run();
104+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
*
3+
* Find KV rating for motor with Hall sensors
4+
*
5+
* Motor KV rating is defiend as the increase of the motor velocity expressed in rotations per minute [rpm] per each 1 Volt int voltage control mode.
6+
*
7+
* This example will set your motor in the torque control mode using voltage and set 1 volt to the motor. By reading the velocity it will calculat the motors KV rating.
8+
* - To make this esimation more credible you can try increasing the target voltage (or decrease in some cases)
9+
* - The KV rating should be realatively static number - it should not change considerably with the increase in the voltage
10+
*/
11+
#include <SimpleFOC.h>
12+
13+
14+
// BLDC motor & driver instance
15+
BLDCMotor motor = BLDCMotor(11);
16+
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
17+
18+
// hall sensor instance
19+
HallSensor sensor = HallSensor(2, 3, 4, 11);
20+
21+
// Interrupt routine intialisation
22+
// channel A and B callbacks
23+
void doA(){sensor.handleA();}
24+
void doB(){sensor.handleB();}
25+
void doC(){sensor.handleC();}
26+
27+
28+
// voltage set point variable
29+
float target_voltage = 1;
30+
31+
// instantiate the commander
32+
Commander command = Commander(Serial);
33+
void doTarget(char* cmd) { command.scalar(&target_voltage, cmd); }
34+
void calcKV(char* cmd) {
35+
// calculate the KV
36+
Serial.println(motor.shaft_velocity/motor.target*30.0f/_PI);
37+
38+
}
39+
40+
void setup() {
41+
42+
// initialize encoder sensor hardware
43+
sensor.init();
44+
sensor.enableInterrupts(doA, doB, doC);
45+
// link the motor to the sensor
46+
motor.linkSensor(&sensor);
47+
48+
// driver config
49+
// power supply voltage [V]
50+
driver.voltage_power_supply = 12;
51+
driver.init();
52+
// link driver
53+
motor.linkDriver(&driver);
54+
55+
// aligning voltage
56+
motor.voltage_sensor_align = 3;
57+
58+
// choose FOC modulation (optional)
59+
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
60+
61+
// set motion control loop to be used
62+
motor.controller = MotionControlType::torque;
63+
64+
// use monitoring with serial
65+
Serial.begin(115200);
66+
// comment out if not needed
67+
motor.useMonitoring(Serial);
68+
69+
// initialize motor
70+
motor.init();
71+
// align sensor and start FOC
72+
motor.initFOC();
73+
74+
// add target command T
75+
command.add('T', doTarget, "target voltage");
76+
command.add('K', calcKV, "calculate KV rating");
77+
78+
Serial.println(F("Motor ready."));
79+
Serial.println(F("Set the target voltage : - commnad T"));
80+
Serial.println(F("Calculate the motor KV : - command K"));
81+
_delay(1000);
82+
}
83+
84+
85+
void loop() {
86+
87+
// main FOC algorithm function
88+
// the faster you run this function the better
89+
// Arduino UNO loop ~1kHz
90+
// Bluepill loop ~10kHz
91+
motor.loopFOC();
92+
93+
// Motion control function
94+
// velocity, position or voltage (defined in motor.controller)
95+
// this function can be run at much lower frequency than loopFOC() function
96+
// You can also use motor.move() and set the motor.target in the code
97+
motor.move(target_voltage);
98+
99+
// user communication
100+
command.run();
101+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* Find KV rating for motor with magnetic sensors
3+
*
4+
* Motor KV rating is defiend as the increase of the motor velocity expressed in rotations per minute [rpm] per each 1 Volt int voltage control mode.
5+
*
6+
* This example will set your motor in the torque control mode using voltage and set 1 volt to the motor. By reading the velocity it will calculat the motors KV rating.
7+
* - To make this esimation more credible you can try increasing the target voltage (or decrease in some cases)
8+
* - The KV rating should be realatively static number - it should not change considerably with the increase in the voltage
9+
*/
10+
#include <SimpleFOC.h>
11+
12+
// magnetic sensor instance - SPI
13+
MagneticSensorSPI sensor = MagneticSensorSPI(AS5147_SPI, 10);
14+
// magnetic sensor instance - I2C
15+
// MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);
16+
// magnetic sensor instance - analog output
17+
// MagneticSensorAnalog sensor = MagneticSensorAnalog(A1, 14, 1020);
18+
19+
// BLDC motor & driver instance
20+
BLDCMotor motor = BLDCMotor(11);
21+
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
22+
// Stepper motor & driver instance
23+
//StepperMotor motor = StepperMotor(50);
24+
//StepperDriver4PWM driver = StepperDriver4PWM(9, 5, 10, 6, 8);
25+
26+
// voltage set point variable
27+
float target_voltage = 1;
28+
29+
// instantiate the commander
30+
Commander command = Commander(Serial);
31+
void doTarget(char* cmd) { command.scalar(&target_voltage, cmd); }
32+
void calcKV(char* cmd) {
33+
// calculate the KV
34+
Serial.println(motor.shaft_velocity/motor.target*30.0f/_PI);
35+
36+
}
37+
38+
void setup() {
39+
40+
// initialize encoder sensor hardware
41+
sensor.init();
42+
sensor.enableInterrupts(doA, doB, doC);
43+
// link the motor to the sensor
44+
motor.linkSensor(&sensor);
45+
46+
// driver config
47+
// power supply voltage [V]
48+
driver.voltage_power_supply = 12;
49+
driver.init();
50+
// link driver
51+
motor.linkDriver(&driver);
52+
53+
// aligning voltage
54+
motor.voltage_sensor_align = 3;
55+
56+
// choose FOC modulation (optional)
57+
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
58+
59+
// set motion control loop to be used
60+
motor.controller = MotionControlType::torque;
61+
62+
// use monitoring with serial
63+
Serial.begin(115200);
64+
// comment out if not needed
65+
motor.useMonitoring(Serial);
66+
67+
// initialize motor
68+
motor.init();
69+
// align sensor and start FOC
70+
motor.initFOC();
71+
72+
// add target command T
73+
command.add('T', doTarget, "target voltage");
74+
command.add('K', calcKV, "calculate KV rating");
75+
76+
Serial.println(F("Motor ready."));
77+
Serial.println(F("Set the target voltage : - commnad T"));
78+
Serial.println(F("Calculate the motor KV : - command K"));
79+
_delay(1000);
80+
}
81+
82+
83+
void loop() {
84+
85+
// main FOC algorithm function
86+
// the faster you run this function the better
87+
// Arduino UNO loop ~1kHz
88+
// Bluepill loop ~10kHz
89+
motor.loopFOC();
90+
91+
// Motion control function
92+
// velocity, position or voltage (defined in motor.controller)
93+
// this function can be run at much lower frequency than loopFOC() function
94+
// You can also use motor.move() and set the motor.target in the code
95+
motor.move(target_voltage);
96+
97+
// user communication
98+
command.run();
99+
}

0 commit comments

Comments
 (0)