Skip to content

Commit 92352b1

Browse files
committed
fix MotorGroup::setAngle
1 parent 7106666 commit 92352b1

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/hardware/Motor/MotorGroup.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ MotorGroup::MotorGroup(std::initializer_list<int> ports, AngularVelocity outputV
1414

1515
MotorGroup::MotorGroup(pros::MotorGroup group, AngularVelocity outputVelocity)
1616
: m_outputVelocity(outputVelocity) {
17-
const std::vector<std::int8_t> ports = group.get_port_all();
18-
for (const int port : ports) {
19-
m_motors.push_back({.port = port, .connectedLastCycle = true, .offset = 0_stDeg});
20-
}
21-
}
17+
const std::vector<std::int8_t> ports = group.get_port_all();
18+
for (const int port : ports) { m_motors.push_back({.port = port, .connectedLastCycle = true, .offset = 0_stDeg}); }
19+
}
2220

2321
int MotorGroup::move(double percent) {
2422
const std::vector<Motor> motors = getMotors();
@@ -101,6 +99,11 @@ int MotorGroup::setAngle(Angle angle) {
10199
for (Motor motor : motors) {
102100
const int result = motor.setAngle(angle);
103101
if (result == 0) success = true;
102+
const Angle offset = motor.getOffset();
103+
// set the offset of that motor
104+
for (MotorInfo& info : m_motors) {
105+
if (info.port == motor.getPort()) info.offset = offset;
106+
}
104107
}
105108
// as long as one motor sets the angle successfully, return 0 (success)
106109
return success ? 0 : INT_MAX;

0 commit comments

Comments
 (0)