Th code compiles without errors

This commit is contained in:
Pascal Serrarens 2025-04-08 11:20:09 +02:00
parent 142ba8377f
commit e472c3626c
4 changed files with 33 additions and 21 deletions

View File

@ -1,15 +1,17 @@
#include "ControlledMotor.h"
ControlledMotor::ControlledMotor() { this->type = Thing::ControlledMotorType; }
namespace RoboidControl {
ControlledMotor::ControlledMotor(Motor *motor, Encoder *encoder)
ControlledMotor::ControlledMotor() { this->type = Thing::ControlledMotor; }
ControlledMotor::ControlledMotor(Motor *motor, IncrementalEncoder *encoder)
: ControlledMotor() {
this->motor = motor;
this->encoder = encoder;
// this->rotationDirection = Direction::Forward;
}
#include <Arduino.h>
//#include <Arduino.h>
void ControlledMotor::SetTargetSpeed(float speed) {
this->currentTargetSpeed = speed;
@ -31,18 +33,18 @@ void ControlledMotor::Update(unsigned long currentTimeMs) {
float delta = error * pidP + errorChange * pidD;
Serial.print(" actual Speed ");
Serial.print(actualSpeed);
Serial.print(" target Speed ");
Serial.print(this->currentTargetSpeed);
Serial.print(" motor target speed ");
Serial.print(motor->currentTargetSpeed);
Serial.print(" + ");
Serial.print(error * pidP);
Serial.print(" + ");
Serial.print(errorChange * pidD);
Serial.print(" = ");
Serial.println(motor->currentTargetSpeed + delta);
// Serial.print(" actual Speed ");
// Serial.print(actualSpeed);
// Serial.print(" target Speed ");
// Serial.print(this->currentTargetSpeed);
// Serial.print(" motor target speed ");
// Serial.print(motor->currentTargetSpeed);
// Serial.print(" + ");
// Serial.print(error * pidP);
// Serial.print(" + ");
// Serial.print(errorChange * pidD);
// Serial.print(" = ");
// Serial.println(motor->currentTargetSpeed + delta);
motor->SetTargetSpeed(motor->currentTargetSpeed +
delta); // or something like that
@ -60,4 +62,6 @@ bool ControlledMotor::Drive(float distance) {
float totalDistance = encoder->GetDistance() - startDistance;
bool completed = totalDistance > targetDistance;
return completed;
}
}

View File

@ -1,4 +1,6 @@
#include "Encoder.h"
#include "IncrementalEncoder.h"
namespace RoboidControl {
IncrementalEncoder::IncrementalEncoder(unsigned char pulsesPerRevolution,
unsigned char distancePerRotation) {
@ -17,3 +19,5 @@ float IncrementalEncoder::GetRevolutionsPerSecond(float currentTimeMs) {
}
float IncrementalEncoder::GetSpeed(float currentTimeMs) { return 0; }
}

View File

@ -2,7 +2,7 @@
#include "Thing.h"
#include <time.h>
//#include <time.h>
namespace RoboidControl {

View File

@ -2,9 +2,11 @@
#include "LinearAlgebra/FloatSingle.h"
namespace RoboidControl {
ServoMotor::ServoMotor()
: Thing(0) { // for now, id should be set properly later
this->type = Thing::ServoType;
this->type = Thing::Servo;
this->controlMode = ControlMode::Position;
this->targetAngle = Angle16();
this->hasTargetAngle = false;
@ -43,12 +45,12 @@ float ServoMotor::GetTargetVelocity() {
return this->targetVelocity;
}
void ServoMotor::Update(unsigned long currentTimeMs) {
void ServoMotor::Update(unsigned long currentTimeMs, bool recurse) {
for (unsigned char childIx = 0; childIx < this->childCount; childIx++) {
Thing* child = this->GetChild(childIx);
if (child != nullptr && child->type == Thing::ServoType) {
if (child != nullptr && child->type == Thing::Servo) {
ServoMotor* servo = (ServoMotor*)child;
servo->Update(currentTimeMs);
servo->Update(currentTimeMs, recurse);
}
}
@ -103,3 +105,5 @@ void ServoMotor::Update(unsigned long currentTimeMs) {
void ServoMotor::SetAngle(Angle16 angle) {
this->actualAngle = angle;
};
}