Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
askuric committed May 2, 2020
2 parents 979f700 + 916cb4d commit 81dfc57
Show file tree
Hide file tree
Showing 49 changed files with 1,936 additions and 870 deletions.
522 changes: 346 additions & 176 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <SimpleFOC.h>
// software interrupt library
#include <PciManager.h>
#include <PciListenerImp.h>

Expand Down Expand Up @@ -47,27 +48,31 @@ void setup() {
// set FOC loop to be used
// ControlType::voltage
// ControlType::velocity
// ControlType::velocity_ultra_slow
// ControlType::angle
motor.controller = ControlType::velocity;

// contoller configuration based on the controll type
// velocity PI controller parameters
// default K=1.0 Ti = 0.003
motor.PI_velocity.K = 0.3;
motor.PI_velocity.Ti = 0.003;
// default P=0.5 I = 10
motor.PI_velocity.P = 0.2;
motor.PI_velocity.I = 20;
//defualt voltage_power_supply/2
motor.PI_velocity.voltage_limit = 6;
// jerk control using voltage voltage ramp
// default value is 300 volts per sec ~ 0.3V per millisecond
motor.PI_velocity.voltage_ramp = 300;
motor.PI_velocity.voltage_ramp = 1000;

// 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;

// use debugging with serial for motor init
// comment out if not needed
motor.useDebugging(Serial);

// link the motor to the sensor
motor.linkEncoder(&encoder);
motor.linkSensor(&encoder);

// intialise motor
motor.init();
Expand Down Expand Up @@ -101,39 +106,9 @@ void loop() {

// function intended to be used with serial plotter to monitor motor variables
// significantly slowing the execution down!!!!
// motor_monitor();
// motor.monitor();
}

// utility function intended to be used with serial plotter to monitor motor variables
// significantly slowing the execution down!!!!
void motor_monitor() {
switch (motor.controller) {
case ControlType::velocity_ultra_slow:
case ControlType::velocity:
Serial.print(motor.voltage_q);
Serial.print("\t");
Serial.print(motor.shaft_velocity_sp);
Serial.print("\t");
Serial.println(motor.shaft_velocity);
break;
case ControlType::angle:
Serial.print(motor.voltage_q);
Serial.print("\t");
Serial.print(motor.shaft_angle_sp);
Serial.print("\t");
Serial.println(motor.shaft_angle);
break;
case ControlType::voltage:
Serial.print(motor.voltage_q);
Serial.print("\t");
Serial.print(motor.shaft_velocity);
Serial.print("\t");
Serial.println(motor.shaft_angle);
break;
}
}


// Serial communication callback function
// gets the target value from the user
void serialEvent() {
Expand All @@ -148,7 +123,7 @@ void serialEvent() {
// end of input
if (inChar == '\n') {
target_velocity = inputString.toFloat();
Serial.print("Tagret velocity: ");
Serial.print("Target velocity: ");
Serial.println(target_velocity);
inputString = "";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include <SimpleFOC.h>
// software interrupt library
#include <PciManager.h>
#include <PciListenerImp.h>

// Only pins 2 and 3 are supported
#define arduinoInt1 2 // Arduino UNO interrupt 0
Expand All @@ -19,12 +22,10 @@ Encoder encoder = Encoder(arduinoInt1, arduinoInt2, 8192, A0);
// channel A and B callbacks
void doA(){encoder.handleA();}
void doB(){encoder.handleB();}
// index calback interrupt code
// please set the right PCINT(0,1,2)_vect parameter
// PCINT0_vect - index pin in between D8 and D13
// PCINT1_vect - index pin in between A0 and A5 (recommended)
// PCINT2_vect - index pin in between D0 and D7
ISR (PCINT1_vect) { encoder.handleIndex(); }
void doIndex(){encoder.handleIndex();}

// If no available hadware interrupt pins use the software interrupt
PciListenerImp listenerIndex(encoder.index_pin, doIndex);

void setup() {
// debugging port
Expand All @@ -41,7 +42,11 @@ void setup() {
encoder.pullup = Pullup::EXTERN;

// initialise encoder hardware
encoder.init(doA, doB);
encoder.init();
// hardware interrupt enable
encoder.enableInterrupts(doA, doB);
// software interrupts
PciManager.registerListener(&listenerIndex);

// power supply voltage
// default 12V
Expand All @@ -50,47 +55,50 @@ void setup() {
// index search velocity - default 1rad/s
motor.index_search_velocity = 1;
// index search PI contoller parameters
// default K=0.5 Ti = 0.01
motor.PI_velocity_index_search.K = 0.1;
motor.PI_velocity_index_search.Ti = 0.01;
// default P=1, I=10
motor.PI_velocity_index_search.P = 1;
motor.PI_velocity_index_search.I = 20;
//motor.PI_velocity_index_search.voltage_limit = 3;
// jerk control using voltage voltage ramp
// default value is 100
motor.PI_velocity_index_search.voltage_ramp = 100;


// set FOC loop to be used
// ControlType::voltage
// ControlType::velocity
// ControlType::velocity_ultra_slow
// ControlType::angle
motor.controller = ControlType::angle;


// contoller configuration based on the controll type
// velocity PI controller parameters
// default K=1.0 Ti = 0.003
motor.PI_velocity.K = 0.3;
motor.PI_velocity.Ti = 0.003;
// default P=0.5 I = 10
motor.PI_velocity.P = 0.2;
motor.PI_velocity.I = 20;
//defualt voltage_power_supply/2
motor.PI_velocity.voltage_limit = 6;
// jerk control using voltage voltage ramp
// default value is 300 volts per sec ~ 0.3V per millisecond
motor.PI_velocity.voltage_ramp = 300;
motor.PI_velocity.voltage_ramp = 1000;

// 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 K=70
motor.P_angle.K = 20;
// default P=20
motor.P_angle.P = 20;
// maximal velocity of the poisiiton control
// default 20
motor.P_angle.velocity_limit = 4;


// use debugging with serial for motor init
// comment out if not needed
motor.useDebugging(Serial);

// link the motor to the sensor
motor.linkEncoder(&encoder);
motor.linkSensor(&encoder);

// intialise motor
motor.init();
Expand Down Expand Up @@ -123,36 +131,7 @@ void loop() {

// function intended to be used with serial plotter to monitor motor variables
// significantly slowing the execution down!!!!
// motor_monitor();
}

// utility function intended to be used with serial plotter to monitor motor variables
// significantly slowing the execution down!!!!
void motor_monitor() {
switch (motor.controller) {
case ControlType::velocity_ultra_slow:
case ControlType::velocity:
Serial.print(motor.voltage_q);
Serial.print("\t");
Serial.print(motor.shaft_velocity_sp);
Serial.print("\t");
Serial.println(motor.shaft_velocity);
break;
case ControlType::angle:
Serial.print(motor.voltage_q);
Serial.print("\t");
Serial.print(motor.shaft_angle_sp);
Serial.print("\t");
Serial.println(motor.shaft_angle);
break;
case ControlType::voltage:
Serial.print(motor.voltage_q);
Serial.print("\t");
Serial.print(motor.shaft_angle);
Serial.print("\t");
Serial.println(motor.shaft_velocity);
break;
}
// motor.monitor();
}

// Serial communication callback function
Expand All @@ -169,7 +148,7 @@ void serialEvent() {
// end of input
if (inChar == '\n') {
target_angle = inputString.toFloat();
Serial.print("Tagret angle: ");
Serial.print("Target angle: ");
Serial.println(target_angle);
inputString = "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,12 @@ BLDCMotor motor = BLDCMotor(9, 5, 6, 11, 8);
// - encA, encB - encoder A and B pins
// - ppr - impulses per rotation (cpr=ppr*4)
// - index pin - (optional input)
Encoder encoder = Encoder(arduinoInt1, arduinoInt2, 8192, A0);
Encoder encoder = Encoder(arduinoInt1, arduinoInt2, 8192);

// Interrupt rutine intialisation
// channel A and B callbacks
void doA(){encoder.handleA();}
void doB(){encoder.handleB();}
// index calback interrupt code
// please set the right PCINT(0,1,2)_vect parameter
// PCINT0_vect - index pin in between D8 and D13
// PCINT1_vect - index pin in between A0 and A5 (recommended)
// PCINT2_vect - index pin in between D0 and D7
ISR (PCINT1_vect) { encoder.handleIndex(); }

void setup() {
// debugging port
Expand All @@ -41,7 +35,9 @@ void setup() {
encoder.pullup = Pullup::EXTERN;

// initialise encoder hardware
encoder.init(doA, doB);
encoder.init();
// hardware interrupt enable
encoder.enableInterrupts(doA, doB);

// power supply voltage
// default 12V
Expand All @@ -50,39 +46,42 @@ void setup() {
// index search velocity - default 1rad/s
motor.index_search_velocity = 1;
// index search PI contoller parameters
// default K=0.5 Ti = 0.01
motor.PI_velocity_index_search.K = 0.1;
motor.PI_velocity_index_search.Ti = 0.01;
// default P=1, I=10
motor.PI_velocity_index_search.P = 1;
motor.PI_velocity_index_search.I = 20;
//motor.PI_velocity_index_search.voltage_limit = 3;
// jerk control using voltage voltage ramp
// default value is 100
motor.PI_velocity_index_search.voltage_ramp = 100;

// set FOC loop to be used
// ControlType::voltage
// ControlType::velocity
// ControlType::velocity_ultra_slow
// ControlType::angle
motor.controller = ControlType::velocity;

// contoller configuration based on the controll type
// velocity PI controller parameters
// default K=1.0 Ti = 0.003
motor.PI_velocity.K = 0.3;
motor.PI_velocity.Ti = 0.003;
// default P=0.5 I = 10
motor.PI_velocity.P = 0.2;
motor.PI_velocity.I = 20;
//defualt voltage_power_supply/2
motor.PI_velocity.voltage_limit = 6;
// jerk control using voltage voltage ramp
// default value is 300 volts per sec ~ 0.3V per millisecond
motor.PI_velocity.voltage_ramp = 300;
motor.PI_velocity.voltage_ramp = 1000;

// 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;

// use debugging with serial for motor init
// comment out if not needed
motor.useDebugging(Serial);

// link the motor to the sensor
motor.linkEncoder(&encoder);
motor.linkSensor(&encoder);
// intialise motor
motor.init();
// align encoder and start FOC
Expand Down Expand Up @@ -121,35 +120,7 @@ void loop() {

// function intended to be used with serial plotter to monitor motor variables
// significantly slowing the execution down!!!!
//motor_monitor();
//motor.monitor();
}

// utility function intended to be used with serial plotter to monitor motor variables
// significantly slowing the execution down!!!!
void motor_monitor() {
switch (motor.controller) {
case ControlType::velocity_ultra_slow:
case ControlType::velocity:
Serial.print(motor.voltage_q);
Serial.print("\t");
Serial.print(motor.shaft_velocity_sp);
Serial.print("\t");
Serial.println(motor.shaft_velocity);
break;
case ControlType::angle:
Serial.print(motor.voltage_q);
Serial.print("\t");
Serial.print(motor.shaft_angle_sp);
Serial.print("\t");
Serial.println(motor.shaft_angle);
break;
case ControlType::voltage:
Serial.print(motor.voltage_q);
Serial.print("\t");
Serial.print(motor.shaft_angle);
Serial.print("\t");
Serial.println(motor.shaft_velocity);
break;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ void setup() {
encoder.pullup = Pullup::EXTERN;

// initialise encoder hardware
encoder.init(doA, doB);
encoder.init();
// hardware interrupt enable
encoder.enableInterrupts(doA, doB);

Serial.println("Encoder ready");
_delay(1000);
Expand Down
Loading

0 comments on commit 81dfc57

Please sign in to comment.