ODrive program

Dependencies:   mbed ODriveLibTest

Committer:
m204517
Date:
Fri Sep 13 05:50:03 2019 +0000
Revision:
1:8e3e04f1a7f0
Parent:
0:763fa4531dbb
modification

Who changed what in which revision?

UserRevisionLine numberNew contents of line
m204517 0:763fa4531dbb 1 #include "mbed.h"
m204517 0:763fa4531dbb 2 #include "ODriveLibTest.h"
m204517 0:763fa4531dbb 3
m204517 0:763fa4531dbb 4 // Serial to the ODrive
m204517 0:763fa4531dbb 5 Serial odrive_serial(p9, p10); //TX (ODrive RX), RX (ODrive TX)
m204517 0:763fa4531dbb 6 Serial PC(USBTX, USBRX); //
m204517 0:763fa4531dbb 7 // Note: you must also connect GND on ODrive to GND on Arduino!
m204517 0:763fa4531dbb 8
m204517 0:763fa4531dbb 9 // ODrive object
m204517 0:763fa4531dbb 10 ODriveLibTest odrive(odrive_serial);
m204517 0:763fa4531dbb 11
m204517 0:763fa4531dbb 12 int main()
m204517 0:763fa4531dbb 13 {
m204517 0:763fa4531dbb 14 // ODrive uses 115200 baud
m204517 0:763fa4531dbb 15 odrive_serial.baud(115200);
m204517 0:763fa4531dbb 16
m204517 0:763fa4531dbb 17 // Serial to PC
m204517 0:763fa4531dbb 18 PC.baud(115200);
m204517 0:763fa4531dbb 19 while (!PC) ; // wait for Arduino Serial Monitor to open
m204517 0:763fa4531dbb 20
m204517 0:763fa4531dbb 21 PC.printf("ODriveArduino");
m204517 0:763fa4531dbb 22 PC.printf("Setting parameters...");
m204517 0:763fa4531dbb 23
m204517 0:763fa4531dbb 24 odrive.SetLimit(0, 22000.0f, 50.0f);
m204517 0:763fa4531dbb 25 odrive.SetLimit(1, 22000.0f, 50.0f);
m204517 0:763fa4531dbb 26 odrive.ODriveInit(0);
m204517 0:763fa4531dbb 27 odrive.ODriveInit(1);
m204517 1:8e3e04f1a7f0 28
m204517 0:763fa4531dbb 29 PC.printf("Ready!");
m204517 0:763fa4531dbb 30
m204517 0:763fa4531dbb 31 while(1) {
m204517 0:763fa4531dbb 32 if (PC.readable()) {
m204517 0:763fa4531dbb 33 char c = PC.getc();
m204517 1:8e3e04f1a7f0 34
m204517 0:763fa4531dbb 35 if( c == 'm' ) {
m204517 0:763fa4531dbb 36 odrive.SetVelocity(0, 12000);
m204517 0:763fa4531dbb 37 odrive.SetVelocity(1, 12000);
m204517 0:763fa4531dbb 38 } else if( c == 'n' ) {
m204517 0:763fa4531dbb 39 odrive.SetVelocity(0, 1200);
m204517 0:763fa4531dbb 40 odrive.SetVelocity(1, 1200);
m204517 0:763fa4531dbb 41 } else if( c == 's' ) {
m204517 0:763fa4531dbb 42 odrive.SetVelocity(0, 0);
m204517 0:763fa4531dbb 43 odrive.SetVelocity(1, 0);
m204517 0:763fa4531dbb 44 }
m204517 0:763fa4531dbb 45 }
m204517 0:763fa4531dbb 46 }
m204517 0:763fa4531dbb 47
m204517 0:763fa4531dbb 48 }