-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from simplefoc/dev
release v2.2.1
- Loading branch information
Showing
52 changed files
with
1,516 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
examples/utils/current_sense_test/generic_current_sense/generic_current_sense.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* An example code for the generic current sensing implementation | ||
*/ | ||
#include <SimpleFOC.h> | ||
|
||
|
||
// user defined function for reading the phase currents | ||
// returning the value per phase in amps | ||
PhaseCurrent_s readCurrentSense(){ | ||
PhaseCurrent_s c; | ||
// dummy example only reading analog pins | ||
c.a = analogRead(A0); | ||
c.b = analogRead(A1); | ||
c.c = analogRead(A2); // if no 3rd current sense set it to 0 | ||
return(c); | ||
} | ||
|
||
// user defined function for intialising the current sense | ||
// it is optional and if provided it will be called in current_sense.init() | ||
void initCurrentSense(){ | ||
pinMode(A0,INPUT); | ||
pinMode(A1,INPUT); | ||
pinMode(A2,INPUT); | ||
} | ||
|
||
|
||
// GenericCurrentSense class constructor | ||
// it receives the user defined callback for reading the current sense | ||
// and optionally the user defined callback for current sense initialisation | ||
GenericCurrentSense current_sense = GenericCurrentSense(readCurrentSense, initCurrentSense); | ||
|
||
|
||
void setup() { | ||
// if callbacks are not provided in the constructor | ||
// they can be assigned directly: | ||
//current_sense.readCallback = readCurrentSense; | ||
//current_sense.initCallback = initCurrentSense; | ||
|
||
// initialise the current sensing | ||
current_sense.init(); | ||
|
||
|
||
Serial.begin(115200); | ||
Serial.println("Current sense ready."); | ||
} | ||
|
||
void loop() { | ||
|
||
PhaseCurrent_s currents = current_sense.getPhaseCurrents(); | ||
float current_magnitude = current_sense.getDCCurrent(); | ||
|
||
Serial.print(currents.a); // milli Amps | ||
Serial.print("\t"); | ||
Serial.print(currents.b); // milli Amps | ||
Serial.print("\t"); | ||
Serial.print(currents.c); // milli Amps | ||
Serial.print("\t"); | ||
Serial.println(current_magnitude); // milli Amps | ||
} |
51 changes: 51 additions & 0 deletions
51
examples/utils/sensor_test/generic_sensor/generic_sensor.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Generic sensor example code | ||
* | ||
* This is a code intended to demonstrate how to implement the generic sensor class | ||
* | ||
*/ | ||
|
||
#include <SimpleFOC.h> | ||
|
||
// sensor reading function example | ||
// for the magnetic sensor with analog communication | ||
// returning an angle in radians in between 0 and 2PI | ||
float readSensor(){ | ||
return analogRead(A0)*_2PI/1024.0; | ||
} | ||
|
||
// sensor intialising function | ||
void initSensor(){ | ||
pinMode(A0,INPUT); | ||
} | ||
|
||
// generic sensor class contructor | ||
// - read sensor callback | ||
// - init sensor callback (optional) | ||
GenericSensor sensor = GenericSensor(readSensor, initSensor); | ||
|
||
void setup() { | ||
// monitoring port | ||
Serial.begin(115200); | ||
|
||
// if callbacks are not provided in the constructor | ||
// they can be assigned directly: | ||
//sensor.readCallback = readSensor; | ||
//sensor.initCallback = initSensor; | ||
|
||
sensor.init(); | ||
|
||
Serial.println("Sensor ready"); | ||
_delay(1000); | ||
} | ||
|
||
void loop() { | ||
// iterative function updating the sensor internal variables | ||
// it is usually called in motor.loopFOC() | ||
sensor.update(); | ||
|
||
// display the angle and the angular velocity to the terminal | ||
Serial.print(sensor.getAngle()); | ||
Serial.print("\t"); | ||
Serial.println(sensor.getVelocity()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=Simple FOC | ||
version=2.2 | ||
version=2.2.1 | ||
author=Simplefoc <[email protected]> | ||
maintainer=Simplefoc <[email protected]> | ||
sentence=A library demistifying FOC for BLDC motors | ||
|
Oops, something went wrong.