Th code compiles without errors
This commit is contained in:
parent
142ba8377f
commit
e472c3626c
@ -1,15 +1,17 @@
|
|||||||
#include "ControlledMotor.h"
|
#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() {
|
: ControlledMotor() {
|
||||||
this->motor = motor;
|
this->motor = motor;
|
||||||
this->encoder = encoder;
|
this->encoder = encoder;
|
||||||
// this->rotationDirection = Direction::Forward;
|
// this->rotationDirection = Direction::Forward;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Arduino.h>
|
//#include <Arduino.h>
|
||||||
|
|
||||||
void ControlledMotor::SetTargetSpeed(float speed) {
|
void ControlledMotor::SetTargetSpeed(float speed) {
|
||||||
this->currentTargetSpeed = speed;
|
this->currentTargetSpeed = speed;
|
||||||
@ -31,18 +33,18 @@ void ControlledMotor::Update(unsigned long currentTimeMs) {
|
|||||||
|
|
||||||
float delta = error * pidP + errorChange * pidD;
|
float delta = error * pidP + errorChange * pidD;
|
||||||
|
|
||||||
Serial.print(" actual Speed ");
|
// Serial.print(" actual Speed ");
|
||||||
Serial.print(actualSpeed);
|
// Serial.print(actualSpeed);
|
||||||
Serial.print(" target Speed ");
|
// Serial.print(" target Speed ");
|
||||||
Serial.print(this->currentTargetSpeed);
|
// Serial.print(this->currentTargetSpeed);
|
||||||
Serial.print(" motor target speed ");
|
// Serial.print(" motor target speed ");
|
||||||
Serial.print(motor->currentTargetSpeed);
|
// Serial.print(motor->currentTargetSpeed);
|
||||||
Serial.print(" + ");
|
// Serial.print(" + ");
|
||||||
Serial.print(error * pidP);
|
// Serial.print(error * pidP);
|
||||||
Serial.print(" + ");
|
// Serial.print(" + ");
|
||||||
Serial.print(errorChange * pidD);
|
// Serial.print(errorChange * pidD);
|
||||||
Serial.print(" = ");
|
// Serial.print(" = ");
|
||||||
Serial.println(motor->currentTargetSpeed + delta);
|
// Serial.println(motor->currentTargetSpeed + delta);
|
||||||
|
|
||||||
motor->SetTargetSpeed(motor->currentTargetSpeed +
|
motor->SetTargetSpeed(motor->currentTargetSpeed +
|
||||||
delta); // or something like that
|
delta); // or something like that
|
||||||
@ -61,3 +63,5 @@ bool ControlledMotor::Drive(float distance) {
|
|||||||
bool completed = totalDistance > targetDistance;
|
bool completed = totalDistance > targetDistance;
|
||||||
return completed;
|
return completed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
#include "Encoder.h"
|
#include "IncrementalEncoder.h"
|
||||||
|
|
||||||
|
namespace RoboidControl {
|
||||||
|
|
||||||
IncrementalEncoder::IncrementalEncoder(unsigned char pulsesPerRevolution,
|
IncrementalEncoder::IncrementalEncoder(unsigned char pulsesPerRevolution,
|
||||||
unsigned char distancePerRotation) {
|
unsigned char distancePerRotation) {
|
||||||
@ -17,3 +19,5 @@ float IncrementalEncoder::GetRevolutionsPerSecond(float currentTimeMs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float IncrementalEncoder::GetSpeed(float currentTimeMs) { return 0; }
|
float IncrementalEncoder::GetSpeed(float currentTimeMs) { return 0; }
|
||||||
|
|
||||||
|
}
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "Thing.h"
|
#include "Thing.h"
|
||||||
|
|
||||||
#include <time.h>
|
//#include <time.h>
|
||||||
|
|
||||||
namespace RoboidControl {
|
namespace RoboidControl {
|
||||||
|
|
||||||
|
@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
#include "LinearAlgebra/FloatSingle.h"
|
#include "LinearAlgebra/FloatSingle.h"
|
||||||
|
|
||||||
|
namespace RoboidControl {
|
||||||
|
|
||||||
ServoMotor::ServoMotor()
|
ServoMotor::ServoMotor()
|
||||||
: Thing(0) { // for now, id should be set properly later
|
: Thing(0) { // for now, id should be set properly later
|
||||||
this->type = Thing::ServoType;
|
this->type = Thing::Servo;
|
||||||
this->controlMode = ControlMode::Position;
|
this->controlMode = ControlMode::Position;
|
||||||
this->targetAngle = Angle16();
|
this->targetAngle = Angle16();
|
||||||
this->hasTargetAngle = false;
|
this->hasTargetAngle = false;
|
||||||
@ -43,12 +45,12 @@ float ServoMotor::GetTargetVelocity() {
|
|||||||
return this->targetVelocity;
|
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++) {
|
for (unsigned char childIx = 0; childIx < this->childCount; childIx++) {
|
||||||
Thing* child = this->GetChild(childIx);
|
Thing* child = this->GetChild(childIx);
|
||||||
if (child != nullptr && child->type == Thing::ServoType) {
|
if (child != nullptr && child->type == Thing::Servo) {
|
||||||
ServoMotor* servo = (ServoMotor*)child;
|
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) {
|
void ServoMotor::SetAngle(Angle16 angle) {
|
||||||
this->actualAngle = angle;
|
this->actualAngle = angle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user