RoboidControl-cpp/Roboid.cpp

41 lines
1.1 KiB
C++

#include "Roboid.h"
#include <Arduino.h>
Roboid::Roboid() {
this->configuration = nullptr;
this->thingCount = 0;
}
Roboid::Roboid(Placement configuration[], unsigned int thingCount) {
this->configuration = configuration;
this->thingCount = thingCount;
perception.AddSensors(configuration, thingCount);
propulsion.AddMotors(configuration, thingCount);
}
bool Roboid::Drive(Waypoint* waypoint) {
bool finished = propulsion.Drive(waypoint->point, waypoint->rotation);
return finished;
}
void Roboid::FollowTrajectory(Trajectory* trajectory) {
this->trajectory = trajectory;
this->waypointIx = 0;
}
void Roboid::Update() {
if (this->trajectory == nullptr)
return;
Waypoint* waypoint = &this->trajectory->waypoints[this->waypointIx];
// Serial.printf("Driving waypoints %d: %f %f\n", this->waypointIx,
// waypoint->point.z, waypoint->rotation);
if (Drive(waypoint)) {
this->waypointIx++;
if (this->waypointIx == this->trajectory->waypointCount) {
this->trajectory = nullptr;
this->waypointIx = 0;
propulsion.SetTwistSpeed(0, 0);
}
}
}