Skip to content

Yann/feature/motors/get consumption #1409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions include/interface/drivers/AnalogIn.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Leka - LekaOS
// Copyright 2024 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#pragma once

namespace leka::interface {

class AnalogIn
{
public:
virtual ~AnalogIn() = default;

virtual auto read() -> float = 0;
};

} // namespace leka::interface
17 changes: 17 additions & 0 deletions include/interface/drivers/MotorConsumption
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Leka - LekaOS
// Copyright 2024 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#pragma once

namespace leka::interface {

class MotorConsumption
{
public:
virtual ~MotorConsumption() = default;

virtual auto getConsumption() -> float = 0;
};

} // namespace leka::interface
22 changes: 15 additions & 7 deletions spikes/lk_motors/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "rtos/ThisThread.h"
#include "rtos/Thread.h"

#include "AnalogIn.h"
#include "CoreMotor.h"
#include "CorePwm.h"
#include "HelloWorld.h"
Expand Down Expand Up @@ -60,6 +61,18 @@ auto main() -> int
auto motor_left = CoreMotor {motor_left_dir_1, motor_left_dir_2, motor_left_speed};
auto motor_right = CoreMotor {motor_right_dir_1, motor_right_dir_2, motor_right_speed};

const auto maxVSense = float {2.3}; // min -1V
auto motor_left_voltage = mbed::AnalogIn {MOTOR_LEFT_VOLTAGE, maxVSense}; // U = RI, R = 0.5

auto log_voltage = [&motor_left_voltage] {
for (int i = 0; i < 20; i++) {
log_info("Raw: %d | Ratio: %.2f | Voltage: %.2fV | Current: %.2fA", motor_left_voltage.read_u16(),
motor_left_voltage.read(), motor_left_voltage.read_voltage(),
motor_left_voltage.read_voltage() * 2.0F);
rtos::ThisThread::sleep_for(100ms);
}
};

while (true) {
auto t = rtos::Kernel::Clock::now() - start;
log_info("A message from your board %s --> \"%s\" at %i s\n", MBED_CONF_APP_TARGET_NAME, hello.world,
Expand All @@ -70,16 +83,11 @@ auto main() -> int
log_info("Spin left...");
spinLeft(motor_left, motor_right);

rtos::ThisThread::sleep_for(5s);

log_info("Spin right...");
spinRight(motor_left, motor_right);

rtos::ThisThread::sleep_for(5s);
log_voltage();

log_info("Spin stop...");
stop(motor_left, motor_right);

rtos::ThisThread::sleep_for(5s);
log_voltage();
}
}
Loading