Michel MOULIN
/
as5048spi_moulin
mesure de l'angle sur AS5048 par SPI
main.cpp@1:d92ff88de240, 2021-11-30 (annotated)
- Committer:
- michelmoulin
- Date:
- Tue Nov 30 13:37:45 2021 +0000
- Revision:
- 1:d92ff88de240
- Parent:
- 0:5a1830df0b66
Lecture de l'angle depuis l'AS5048 en SPI
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
PC2ROBOT | 0:5a1830df0b66 | 1 | #include "mbed.h" |
PC2ROBOT | 0:5a1830df0b66 | 2 | #include "as5048spi.h" |
PC2ROBOT | 0:5a1830df0b66 | 3 | |
PC2ROBOT | 0:5a1830df0b66 | 4 | #define pi 3.14159 |
PC2ROBOT | 0:5a1830df0b66 | 5 | |
PC2ROBOT | 0:5a1830df0b66 | 6 | As5048Spi sensor(PB_15, PB_14, PB_13, PB_12); //MOSI, MISO, SCKL, CS |
PC2ROBOT | 0:5a1830df0b66 | 7 | Serial pc(USBTX, USBRX); // tx, rx |
michelmoulin | 1:d92ff88de240 | 8 | |
michelmoulin | 1:d92ff88de240 | 9 | float mesure_angle_encodeur(); |
PC2ROBOT | 0:5a1830df0b66 | 10 | |
michelmoulin | 1:d92ff88de240 | 11 | float mesure_angle_encodeur() |
PC2ROBOT | 0:5a1830df0b66 | 12 | { |
michelmoulin | 1:d92ff88de240 | 13 | int angle; |
PC2ROBOT | 0:5a1830df0b66 | 14 | const int* angles = sensor.read_angle(); |
PC2ROBOT | 0:5a1830df0b66 | 15 | angle = angles[0]; |
michelmoulin | 1:d92ff88de240 | 16 | float degre; |
PC2ROBOT | 0:5a1830df0b66 | 17 | |
michelmoulin | 1:d92ff88de240 | 18 | //Aquisition de l'angle |
michelmoulin | 1:d92ff88de240 | 19 | degre = sensor.degrees(angle)/100.0; |
michelmoulin | 1:d92ff88de240 | 20 | return degre; |
PC2ROBOT | 0:5a1830df0b66 | 21 | } |
PC2ROBOT | 0:5a1830df0b66 | 22 | |
PC2ROBOT | 0:5a1830df0b66 | 23 | int main() { |
michelmoulin | 1:d92ff88de240 | 24 | float angle_encodeur; |
PC2ROBOT | 0:5a1830df0b66 | 25 | while(1) |
PC2ROBOT | 0:5a1830df0b66 | 26 | { |
michelmoulin | 1:d92ff88de240 | 27 | angle_encodeur = mesure_angle_encodeur(); |
michelmoulin | 1:d92ff88de240 | 28 | pc.printf("angle = %.2f degrees \n\r", angle_encodeur); |
michelmoulin | 1:d92ff88de240 | 29 | wait(1); |
PC2ROBOT | 0:5a1830df0b66 | 30 | } |
PC2ROBOT | 0:5a1830df0b66 | 31 | } |