From e472c3626c498c91f18963ad40d06cff5a808725 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Tue, 8 Apr 2025 11:20:09 +0200 Subject: [PATCH] Th code compiles without errors --- Things/ControlledMotor.cpp | 34 +++++++++++++++++++--------------- Things/IncrementalEncoder.cpp | 6 +++++- Things/Motor.h | 2 +- Things/ServoMotor.cpp | 12 ++++++++---- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/Things/ControlledMotor.cpp b/Things/ControlledMotor.cpp index bec227e..d5ef518 100644 --- a/Things/ControlledMotor.cpp +++ b/Things/ControlledMotor.cpp @@ -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 +//#include 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; +} + } \ No newline at end of file diff --git a/Things/IncrementalEncoder.cpp b/Things/IncrementalEncoder.cpp index 2da89b8..ea59b48 100644 --- a/Things/IncrementalEncoder.cpp +++ b/Things/IncrementalEncoder.cpp @@ -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; } + +} \ No newline at end of file diff --git a/Things/Motor.h b/Things/Motor.h index 9893cb3..d05f5f6 100644 --- a/Things/Motor.h +++ b/Things/Motor.h @@ -2,7 +2,7 @@ #include "Thing.h" -#include +//#include namespace RoboidControl { diff --git a/Things/ServoMotor.cpp b/Things/ServoMotor.cpp index 4f99da7..b8f111d 100644 --- a/Things/ServoMotor.cpp +++ b/Things/ServoMotor.cpp @@ -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; }; + +} \ No newline at end of file