Fix not all servos in tree moving

This commit is contained in:
Pascal Serrarens 2024-01-31 12:13:13 +01:00
parent 8672e1519a
commit 4776907262
2 changed files with 12 additions and 13 deletions

View File

@ -42,9 +42,15 @@ void ServoMotor::SetTargetVelocity(float targetVelocity) {
float ServoMotor::GetTargetVelocity() { return this->targetVelocity; }
#include <Arduino.h>
void ServoMotor::Update(float currentTimeMs) {
for (unsigned char childIx = 0; childIx < this->childCount; childIx++) {
Thing *child = this->GetChild(childIx);
if (child != nullptr && child->type == Thing::ServoType) {
ServoMotor *servo = (ServoMotor *)child;
servo->Update(currentTimeMs);
}
}
if (this->lastUpdateTimeMs == 0 || currentTimeMs < this->lastUpdateTimeMs) {
this->lastUpdateTimeMs = currentTimeMs;
return;
@ -52,6 +58,7 @@ void ServoMotor::Update(float currentTimeMs) {
float deltaTime = (currentTimeMs - this->lastUpdateTimeMs) / 1000.0F;
// Position control
if (controlMode == ControlMode::Position) {
if (maxVelocity == 0.0F || hasTargetAngle == false) {
this->lastUpdateTimeMs = currentTimeMs;
@ -77,7 +84,8 @@ void ServoMotor::Update(float currentTimeMs) {
return;
}
} else { // Velocity Control
// Velocity control
} else {
float newAngle = this->targetAngle + targetVelocity * deltaTime;
newAngle = Float::Clamp(newAngle, minAngle, maxAngle);
@ -86,13 +94,4 @@ void ServoMotor::Update(float currentTimeMs) {
this->lastUpdateTimeMs = currentTimeMs;
}
Serial.println(this->childCount);
for (unsigned char childIx = 0; childIx < this->childCount; childIx++) {
Thing *child = this->GetChild(childIx);
if (child->type == Thing::ServoType) {
ServoMotor *servo = (ServoMotor *)child;
servo->Update(currentTimeMs);
}
}
}

@ -1 +1 @@
Subproject commit 78106912a9e80c1ace5533615cab0bd4a00657a0
Subproject commit 596e85d3a41f5f25b6185f2ca4fb18a2140afca1