-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read values from VESC motor controller
Change-Id: Icaad5bd270827f1fa1b22a77d0cd0e23dbf999e5
- Loading branch information
Showing
4 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,58 @@ | ||
#include "third_party/vesc_uart/VescUart.h" | ||
//#include "" | ||
|
||
#include <cstdint> | ||
#include <fmt/core.h> | ||
#include <fmt/ranges.h> | ||
#include <chrono> | ||
#include <thread> | ||
#include <array> | ||
#include <span> | ||
|
||
auto buffer = std::array<std::uint8_t, 256>{}; | ||
|
||
auto read_payload(std::span<std::uint8_t> buf) -> void | ||
{ | ||
static constexpr auto serial_device = 0; | ||
|
||
static auto cmd_get_values = std::uint8_t{ COMM_GET_VALUES }; | ||
::PackSendPayload(&cmd_get_values, sizeof(cmd_get_values), serial_device); | ||
|
||
{ | ||
const auto version = Serial.read(); | ||
assert(version == 2 and "only version 2 is handled"); | ||
} | ||
|
||
const auto payload_size = Serial.read(); | ||
static constexpr auto footer_size = 3; | ||
|
||
fmt::print("payload_size: {}\n", payload_size); | ||
|
||
const auto message = std::span{buf.data(), std::size_t(payload_size + footer_size)}; | ||
Serial.read(message); | ||
|
||
const auto front = std::span{buf.data(), | ||
//2 + 2 + 4 + 4 + 4 + 4 + 2 + 4 | ||
30 | ||
}; | ||
fmt::print("{::0<2X}\n", front); | ||
// https://github.com/vedderb/bldc/blob/master/comm/commands.c#L379 | ||
} | ||
|
||
auto main() -> int | ||
{ | ||
::VescUartSetCurrent(1.0F); | ||
const auto current = -10.0F; | ||
//const auto data = std::span{reinterpret_cast<const std::uint8_t*>(¤t), sizeof(current)}; | ||
|
||
while (true) { | ||
//::VescUartSetCurrent(current += 1.0F); | ||
::VescUartSetCurrent(current); | ||
fmt::print("current: {}\n", std::int16_t(current)); | ||
|
||
read_payload({buffer.data(), buffer.size()}); | ||
|
||
std::this_thread::sleep_for(std::chrono::milliseconds{100}); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters