|
1 | 1 | /*
|
2 | 2 | Odrive robotics' hardware is one of the best BLDC motor foc supporting hardware out there.
|
3 | 3 |
|
4 |
| - This is an example code that can be directly uploaded to the Odrive usind the SWD programmer. |
| 4 | + This is an example code that can be directly uploaded to the Odrive using the SWD programmer. |
5 | 5 | This code uses an encoder with 500 cpr and a BLDC motor with 7 pole pairs connected to the M0 interface of the Odrive.
|
6 | 6 |
|
7 | 7 | This is a short template code and the idea is that you are able to adapt to your needs not to be a complete solution. :D
|
@@ -49,6 +49,11 @@ BLDCDriver6PWM driver = BLDCDriver6PWM(M0_INH_A,M0_INL_A, M0_INH_B,M0_INL_B, M0_
|
49 | 49 | Commander command = Commander(Serial);
|
50 | 50 | void doMotor(char* cmd) { command.motor(&motor, cmd); }
|
51 | 51 |
|
| 52 | +// low side current sensing define |
| 53 | +// 0.0005 Ohm resistor |
| 54 | +// gain of 10x |
| 55 | +// current sensing on B and C phases, phase A not connected |
| 56 | +LowsideCurrentSense current_sense = LowsideCurrentSense(0.0005f, 10.0f, _NC, M0_IB, M0_IC); |
52 | 57 |
|
53 | 58 | Encoder encoder = Encoder(M0_ENC_A, M0_ENC_B, 500);
|
54 | 59 | // Interrupt routine intialisation
|
@@ -88,18 +93,29 @@ void setup(){
|
88 | 93 | Serial.begin(115200);
|
89 | 94 | // comment out if not needed
|
90 | 95 | motor.useMonitoring(Serial);
|
91 |
| - motor.monitor_downsample = 0; // disable monitoring at start |
| 96 | + motor.monitor_variables = _MON_CURR_Q | _MON_CURR_D; |
| 97 | + motor.monitor_downsample = 1000; |
92 | 98 |
|
93 | 99 | // add target command T
|
94 | 100 | command.add('M', doMotor, "motor M0");
|
95 | 101 |
|
96 | 102 | // initialise motor
|
97 | 103 | motor.init();
|
| 104 | + |
| 105 | + // link the driver |
| 106 | + current_sense.linkDriver(&driver); |
| 107 | + // init the current sense |
| 108 | + current_sense.init(); |
| 109 | + current_sense.skip_align = true; |
| 110 | + motor.linkCurrentSense(¤t_sense); |
| 111 | + |
98 | 112 | // init FOC
|
99 | 113 | motor.initFOC();
|
100 | 114 | delay(1000);
|
101 | 115 | }
|
| 116 | + |
102 | 117 | void loop(){
|
| 118 | + |
103 | 119 | // foc loop
|
104 | 120 | motor.loopFOC();
|
105 | 121 | // motion control
|
|
0 commit comments