mirror of
https://github.com/YikeStone/ros_arduino_bridge.git
synced 2025-08-03 19:24:09 +05:30
Added check for duplicate servo pins in servo array
This commit is contained in:
parent
932282526d
commit
4fd35aa2b5
@ -194,8 +194,10 @@ int runCommand() {
|
||||
#elif defined(USE_SERVOS2)
|
||||
case CONFIG_SERVO:
|
||||
myServos[arg1].initServo(arg1, arg2);
|
||||
myServoPins[nServos] = arg1;
|
||||
nServos++;
|
||||
if (!haveServo(arg1)) {
|
||||
myServoPins[nServos] = arg1;
|
||||
nServos++;
|
||||
}
|
||||
Serial.println("OK");
|
||||
break;
|
||||
case SERVO_WRITE:
|
||||
|
@ -18,7 +18,7 @@
|
||||
// Constructor
|
||||
SweepServo2::SweepServo2()
|
||||
{
|
||||
this->currentPositionDegrees = 0;
|
||||
this->currentPositionDegrees = 90;
|
||||
this->targetPositionDegrees = 90;
|
||||
this->lastSweepCommand = 0;
|
||||
}
|
||||
@ -29,7 +29,7 @@ void SweepServo2::initServo(
|
||||
int stepDelayMs)
|
||||
{
|
||||
this->stepDelayMs = stepDelayMs;
|
||||
this->currentPositionDegrees = 0;
|
||||
this->currentPositionDegrees = 90;
|
||||
this->targetPositionDegrees = 90;
|
||||
this->lastSweepCommand = millis();
|
||||
this->servo.attach(servoPin);
|
||||
@ -74,11 +74,21 @@ void SweepServo2::setTargetPosition(int position)
|
||||
this->targetPositionDegrees = position;
|
||||
}
|
||||
|
||||
// Get the current servo position
|
||||
int SweepServo2::getCurrentPosition()
|
||||
{
|
||||
return this->currentPositionDegrees;
|
||||
}
|
||||
|
||||
// Check whether we have already configured this servo
|
||||
bool haveServo(int pin) {
|
||||
int i;
|
||||
for (i = 0; i < nServos; i++) {
|
||||
if (myServoPins[i] == pin) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Accessor for servo object
|
||||
Servo SweepServo2::getServo()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user