Skip to content

Commit 9fbbf46

Browse files
committed
odrive example with current sesning
1 parent bdc9591 commit 9fbbf46

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

examples/hardware_specific_examples/odrive_example/odrive_example.ino

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
Odrive robotics' hardware is one of the best BLDC motor foc supporting hardware out there.
33
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.
55
This code uses an encoder with 500 cpr and a BLDC motor with 7 pole pairs connected to the M0 interface of the Odrive.
66
77
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_
4949
Commander command = Commander(Serial);
5050
void doMotor(char* cmd) { command.motor(&motor, cmd); }
5151

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);
5257

5358
Encoder encoder = Encoder(M0_ENC_A, M0_ENC_B, 500);
5459
// Interrupt routine intialisation
@@ -88,18 +93,29 @@ void setup(){
8893
Serial.begin(115200);
8994
// comment out if not needed
9095
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;
9298

9399
// add target command T
94100
command.add('M', doMotor, "motor M0");
95101

96102
// initialise motor
97103
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(&current_sense);
111+
98112
// init FOC
99113
motor.initFOC();
100114
delay(1000);
101115
}
116+
102117
void loop(){
118+
103119
// foc loop
104120
motor.loopFOC();
105121
// motion control

0 commit comments

Comments
 (0)