@@ -129,10 +129,23 @@ void ExpansionHubState::SendCommands(bool canEnable, bool deviceReset) {
129129 }
130130 }
131131
132- // First the 4 motors.
132+ // Compute motor powers
133+ std::pair<double , int > motorPowers[NUM_MOTORS_PER_HUB];
133134 for (int i = 0 ; i < NUM_MOTORS_PER_HUB; i++) {
134- currentHub->SendMotorConstantPower (
135- i, ntStore.motors [i].ComputeMotorPower (ntStore.lastBattery ));
135+ motorPowers[i] =
136+ ntStore.motors [i].ComputeMotorPower (ntStore.lastBattery );
137+ }
138+
139+ // Then send the 4 motors.
140+ for (int i = 0 ; i < NUM_MOTORS_PER_HUB; i++) {
141+ if (motorPowers[i].second < 0 ) {
142+ currentHub->SendMotorConstantPower (i, motorPowers[i].first );
143+ } else if (motorPowers[i].second < 4 ) {
144+ // TODO, determine if a follower is following a follower, and what to do
145+ currentHub->SendMotorConstantPower (i, motorPowers[motorPowers[i].second ].first );
146+ } else {
147+ currentHub->SendMotorConstantPower (i, 0.0 );
148+ }
136149 }
137150
138151 // Then get the motor currents
@@ -175,7 +188,8 @@ void ExpansionHubState::SendCommands(bool canEnable, bool deviceReset) {
175188 currentHub->Flush ();
176189}
177190
178- void ExpansionHubState::OnDeviceAdded (std::unique_ptr<eh::ExpansionHubSerial> hub) {
191+ void ExpansionHubState::OnDeviceAdded (
192+ std::unique_ptr<eh::ExpansionHubSerial> hub) {
179193 currentHub = std::move (hub);
180194
181195 ntStore.Initialize (*ntInstance, busId);
@@ -275,7 +289,8 @@ static void OnDeviceAdded(wpi::uv::Loop& loop,
275289 return ;
276290 }
277291
278- std::unique_ptr<eh::ExpansionHubSerial> sl = std::make_unique<eh::ExpansionHubSerial>();
292+ std::unique_ptr<eh::ExpansionHubSerial> sl =
293+ std::make_unique<eh::ExpansionHubSerial>();
279294 bool isInit = sl->Initialize (loop, ret, devPath);
280295 printf (" initialized %d\n " , isInit ? 1 : 0 );
281296
@@ -341,8 +356,8 @@ int main() {
341356 };
342357
343358 bool success = false ;
344- loopRunner.ExecSync ([&success, &states, &loopStorage, &ntInst,
345- &usbMonitor, & enabledState](wpi::uv::Loop& loop) {
359+ loopRunner.ExecSync ([&success, &states, &loopStorage, &ntInst, &usbMonitor,
360+ &enabledState](wpi::uv::Loop& loop) {
346361 loopStorage.loop = &loop;
347362 for (size_t i = 0 ; i < states.size (); i++) {
348363 success = states[i].StartUvLoop (i, ntInst, loop);
0 commit comments