Servo control

This commit is contained in:
2025-07-15 10:59:48 -04:00
parent c1d9a3a8b4
commit 15a0f38bac
20 changed files with 309 additions and 531 deletions

View File

@@ -9,8 +9,10 @@
#include "flatbuffers_generated/RobotModule_generated.h"
inline std::unordered_map<int, int> MODULE_TO_NUM_CHANNELS_MAP {{ModuleType_SPLITTER, 4}, {ModuleType_SERVO_1, 2}, {ModuleType_DC_MOTOR, 1}};
inline std::unordered_map<int, int> MODULE_TO_NUM_CHANNELS_MAP {{ModuleType_SPLITTER, 2}, {ModuleType_SERVO_1, 2}, {ModuleType_DC_MOTOR, 1}};
#define PC_ADDR 0
#define SERVO_GPIO 18
#endif //MODULE_H

View File

@@ -0,0 +1,11 @@
//
// Created by Johnathon Slightham on 2025-06-30.
//
#include "AngleControlMessageBuilder.h"
namespace Flatbuffers {
const Messaging::AngleControlMessage* AngleControlMessageBuilder::parse_angle_control_message(const uint8_t* buffer) {
return flatbuffers::GetRoot<Messaging::AngleControlMessage>(buffer);
}
}

View File

@@ -1,2 +1,2 @@
idf_component_register(SRCS "MPIMessageBuilder.cpp"
idf_component_register(SRCS "MPIMessageBuilder.cpp" "AngleControlMessageBuilder.cpp"
INCLUDE_DIRS "include")

View File

@@ -0,0 +1,22 @@
//
// Created by Johnathon Slightham on 2025-06-30.
//
#ifndef ANGLECONTROLMESSAGEBUILDER_H_
#define ANGLECONTROLMESSAGEBUILDER_H_
#include <string>
#include <vector>
#include "SerializedMessage.h"
#include "flatbuffers_generated/AngleControlMessage_generated.h"
#include "flatbuffers/flatbuffers.h"
namespace Flatbuffers {
class AngleControlMessageBuilder {
public:
static const Messaging::AngleControlMessage* parse_angle_control_message(const uint8_t* buffer);
};
}
#endif

View File

@@ -0,0 +1,94 @@
// automatically generated by the FlatBuffers compiler, do not modify
#ifndef FLATBUFFERS_GENERATED_ANGLECONTROLMESSAGE_MESSAGING_H_
#define FLATBUFFERS_GENERATED_ANGLECONTROLMESSAGE_MESSAGING_H_
#include "flatbuffers/flatbuffers.h"
// Ensure the included flatbuffers.h is the same version as when this file was
// generated, otherwise it may not be compatible.
//static_assert(FLATBUFFERS_VERSION_MAJOR == 25 &&
//FLATBUFFERS_VERSION_MINOR == 2 &&
//FLATBUFFERS_VERSION_REVISION == 10,
//"Non-compatible flatbuffers version included");
namespace Messaging {
struct AngleControlMessage;
struct AngleControlMessageBuilder;
struct AngleControlMessage FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
typedef AngleControlMessageBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_ANGLE = 4
};
int16_t angle() const {
return GetField<int16_t>(VT_ANGLE, 0);
}
bool Verify(::flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<int16_t>(verifier, VT_ANGLE, 2) &&
verifier.EndTable();
}
};
struct AngleControlMessageBuilder {
typedef AngleControlMessage Table;
::flatbuffers::FlatBufferBuilder &fbb_;
::flatbuffers::uoffset_t start_;
void add_angle(int16_t angle) {
fbb_.AddElement<int16_t>(AngleControlMessage::VT_ANGLE, angle, 0);
}
explicit AngleControlMessageBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
::flatbuffers::Offset<AngleControlMessage> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = ::flatbuffers::Offset<AngleControlMessage>(end);
return o;
}
};
inline ::flatbuffers::Offset<AngleControlMessage> CreateAngleControlMessage(
::flatbuffers::FlatBufferBuilder &_fbb,
int16_t angle = 0) {
AngleControlMessageBuilder builder_(_fbb);
builder_.add_angle(angle);
return builder_.Finish();
}
inline const Messaging::AngleControlMessage *GetAngleControlMessage(const void *buf) {
return ::flatbuffers::GetRoot<Messaging::AngleControlMessage>(buf);
}
inline const Messaging::AngleControlMessage *GetSizePrefixedAngleControlMessage(const void *buf) {
return ::flatbuffers::GetSizePrefixedRoot<Messaging::AngleControlMessage>(buf);
}
inline bool VerifyAngleControlMessageBuffer(
::flatbuffers::Verifier &verifier) {
return verifier.VerifyBuffer<Messaging::AngleControlMessage>(nullptr);
}
inline bool VerifySizePrefixedAngleControlMessageBuffer(
::flatbuffers::Verifier &verifier) {
return verifier.VerifySizePrefixedBuffer<Messaging::AngleControlMessage>(nullptr);
}
inline void FinishAngleControlMessageBuffer(
::flatbuffers::FlatBufferBuilder &fbb,
::flatbuffers::Offset<Messaging::AngleControlMessage> root) {
fbb.Finish(root);
}
inline void FinishSizePrefixedAngleControlMessageBuffer(
::flatbuffers::FlatBufferBuilder &fbb,
::flatbuffers::Offset<Messaging::AngleControlMessage> root) {
fbb.FinishSizePrefixed(root);
}
} // namespace Messaging
#endif // FLATBUFFERS_GENERATED_ANGLECONTROLMESSAGE_MESSAGING_H_

View File

@@ -1,5 +1,6 @@
#include "CommunicationRouter.h"
#include <AngleControlMessageBuilder.h>
#include <iostream>
#include "mDNSDiscoveryService.h"
#include "MPIMessageBuilder.h"
@@ -101,6 +102,11 @@ void CommunicationRouter::route(uint8_t* buffer, const size_t length) const {
if (mpi_message->destination() == m_module_id) {
std::cout << "Routing to this module [dest:" << static_cast<int>(mpi_message->destination()) << ", length: " << length << "]" << std::endl;
const auto temp = Flatbuffers::AngleControlMessageBuilder::parse_angle_control_message(reinterpret_cast<const uint8_t *>(mpi_message->payload()))->angle();
std::cout << "angle from before router" << temp << std::endl;
this->m_rx_callback(reinterpret_cast<char *>(buffer), 512);
} else if (mpi_message->destination() == PC_ADDR && this->m_leader == m_module_id) {
std::cout << "Routing to wifi [dest:" << static_cast<int>(mpi_message->destination()) << ", length: " << length << "]" << std::endl;

View File

@@ -4,6 +4,7 @@
#include "MessagingInterface.h"
#include <AngleControlMessageBuilder.h>
#include <ConfigManager.h>
#include <freertos/queue.h>
#include <freertos/semphr.h>
@@ -53,7 +54,11 @@ void MessagingInterface::handleRecv(const char* recv_buffer, int recv_size) {
checkOrInsertTag(mpi_message->tag());
xQueueSendToBack(m_tag_to_queue.at(mpi_message->tag()), mpi_message->payload(), 0);
const auto temp = Flatbuffers::AngleControlMessageBuilder::parse_angle_control_message(reinterpret_cast<const uint8_t *>(mpi_message->payload()))->angle();
std::cout << "angle from before queue " << temp << std::endl;
xQueueSendToBack(m_tag_to_queue.at(mpi_message->tag()), mpi_message->payload()->data(), 0);
}
void MessagingInterface::checkOrInsertTag(const uint8_t tag) {