try to fix submodule

This commit is contained in:
2023-11-09 19:02:15 -05:00
parent c1d45aa443
commit deea94b076
366 changed files with 40228 additions and 2 deletions

View File

@@ -0,0 +1,53 @@
/**
* Simple example of custom commands that have nothing to do with the simple foc library
*/
#include <SimpleFOC.h>
// instantiate the commander
Commander command = Commander(Serial);
// led control function
void doLed(char* cmd){
if(atoi(cmd)) digitalWrite(LED_BUILTIN, HIGH);
else digitalWrite(LED_BUILTIN, LOW);
};
// get analog input
void doAnalog(char* cmd){
if (cmd[0] == '0') Serial.println(analogRead(A0));
else if (cmd[0] == '1') Serial.println(analogRead(A1));
else if (cmd[0] == '2') Serial.println(analogRead(A2));
else if (cmd[0] == '3') Serial.println(analogRead(A3));
else if (cmd[0] == '4') Serial.println(analogRead(A4));
};
void setup() {
// define pins
pinMode(LED_BUILTIN, OUTPUT);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
pinMode(A4, INPUT);
// Serial port to be used
Serial.begin(115200);
// add new commands
command.add('L', doLed, "led on/off");
command.add('A', doAnalog, "analog read A0-A4");
Serial.println(F("Commander listening"));
Serial.println(F(" - Send ? to see the node list..."));
Serial.println(F(" - Send L0 to turn the led off and L1 to turn it off"));
Serial.println(F(" - Send A0-A4 to read the analog pins"));
_delay(1000);
}
void loop() {
// user communication
command.run();
_delay(10);
}

View File

@@ -0,0 +1,51 @@
/**
* Simple example of how to use the commander without serial - using just strings
*/
#include <SimpleFOC.h>
// instantiate the commander
Commander command = Commander();
// led control function
void doLed(char* cmd){
if(atoi(cmd)) digitalWrite(LED_BUILTIN, HIGH);
else digitalWrite(LED_BUILTIN, LOW);
};
// get analog input
void doAnalog(char* cmd){
if (cmd[0] == '0') Serial.println(analogRead(A0));
else if (cmd[0] == '1') Serial.println(analogRead(A1));
};
void setup() {
// define pins
pinMode(LED_BUILTIN, OUTPUT);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
// Serial port to be used
Serial.begin(115200);
// add new commands
command.add('L', doLed, "led control");
command.add('A', doAnalog, "analog read A0-A1");
Serial.println(F("Commander running"));
_delay(1000);
}
void loop() {
// user communication
command.run("?");
_delay(2000);
command.run("L0");
_delay(1000);
command.run("A0");
_delay(1000);
command.run("A1");
_delay(1000);
command.run("L1");
_delay(1000);
}

View File

@@ -0,0 +1,79 @@
/**
* A simple example to show how to use the commander with the control loops outside of the scope of the SimpleFOC library
*/
#include <SimpleFOC.h>
// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(11);
BLDCDriver3PWM driver = BLDCDriver3PWM(5, 10, 6, 8);
// encoder instance
Encoder encoder = Encoder(2, 3, 500);
// channel A and B callbacks
void doA() { encoder.handleA(); }
void doB() { encoder.handleB(); }
// target voltage to be set to the motor
float target_velocity = 0;
// PID controllers and low pass filters
PIDController PIDv{0.05, 1, 0, 100000000, 12};
LowPassFilter LPFv{0.01};
//add communication
Commander command = Commander(Serial);
void doController(char* cmd) { command.pid(&PIDv, cmd); }
void doFilter(char* cmd) { command.lpf(&LPFv, cmd); }
void doTarget(char* cmd) { command.scalar(&target_velocity, cmd); }
void setup() {
// initialize encoder sensor hardware
encoder.init();
encoder.enableInterrupts(doA, doB);
// link the motor to the sensor
motor.linkSensor(&encoder);
// driver config
// power supply voltage [V]
driver.init();
// link driver
motor.linkDriver(&driver);
// set motion control loop to be used ( doing nothing )
motor.torque_controller = TorqueControlType::voltage;
motor.controller = MotionControlType::torque;
// use monitoring with serial
Serial.begin(115200);
motor.useMonitoring(Serial);
// initialize motor
motor.init();
// align sensor and start FOC
motor.initFOC();
// subscribe the new commands
command.add('C', doController, "tune velocity pid");
command.add('F', doFilter, "tune velocity LPF");
command.add('T', doTarget, "motor target");
_delay(1000);
Serial.println(F("Commander listening"));
Serial.println(F(" - Send ? to see the node list..."));
}
void loop() {
// looping foc
motor.loopFOC();
// calculate voltage
float target_voltage = PIDv(target_velocity - LPFv(motor.shaft_velocity));
// set the voltage
motor.move(target_voltage);
// user communication
command.run();
}