Skip to content

Commit f16a0b8

Browse files
committed
spike to observe motor consumption
1 parent 230dff4 commit f16a0b8

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

spikes/lk_motors/main.cpp

+15-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "rtos/ThisThread.h"
1111
#include "rtos/Thread.h"
1212

13+
#include "AnalogIn.h"
1314
#include "CoreMotor.h"
1415
#include "CorePwm.h"
1516
#include "HelloWorld.h"
@@ -60,6 +61,18 @@ auto main() -> int
6061
auto motor_left = CoreMotor {motor_left_dir_1, motor_left_dir_2, motor_left_speed};
6162
auto motor_right = CoreMotor {motor_right_dir_1, motor_right_dir_2, motor_right_speed};
6263

64+
const auto maxVSense = float {2.3}; // min -1V
65+
auto motor_left_voltage = mbed::AnalogIn {MOTOR_LEFT_VOLTAGE, maxVSense}; // U = RI, R = 0.5
66+
67+
auto log_voltage = [&motor_left_voltage] {
68+
for (int i = 0; i < 20; i++) {
69+
log_info("Raw: %d | Ratio: %.2f | Voltage: %.2fV | Current: %.2fA", motor_left_voltage.read_u16(),
70+
motor_left_voltage.read(), motor_left_voltage.read_voltage(),
71+
motor_left_voltage.read_voltage() * 2.0F);
72+
rtos::ThisThread::sleep_for(100ms);
73+
}
74+
};
75+
6376
while (true) {
6477
auto t = rtos::Kernel::Clock::now() - start;
6578
log_info("A message from your board %s --> \"%s\" at %i s\n", MBED_CONF_APP_TARGET_NAME, hello.world,
@@ -70,16 +83,11 @@ auto main() -> int
7083
log_info("Spin left...");
7184
spinLeft(motor_left, motor_right);
7285

73-
rtos::ThisThread::sleep_for(5s);
74-
75-
log_info("Spin right...");
76-
spinRight(motor_left, motor_right);
77-
78-
rtos::ThisThread::sleep_for(5s);
86+
log_voltage();
7987

8088
log_info("Spin stop...");
8189
stop(motor_left, motor_right);
8290

83-
rtos::ThisThread::sleep_for(5s);
91+
log_voltage();
8492
}
8593
}

0 commit comments

Comments
 (0)