Skip to content

Commit

Permalink
off by one bug caused readings to be out of order (#806)
Browse files Browse the repository at this point in the history
  • Loading branch information
lkunelk authored Jul 20, 2023
1 parent 7efd0c3 commit 5509c07
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions soccer_firmware/.settings/language.settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1784325041921134830" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-260604961516797221" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
Expand All @@ -16,10 +16,10 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1784325041921134830" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-260604961516797221" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
</project>
</project>
7 changes: 4 additions & 3 deletions soccer_firmware/Core/Src/update_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ void read_imu(uint8_t *rxBuf) {
}

void read_motors(uint8_t *rxBuf) {
for (uint16_t i = 1; i < 6; i++) {// reset variables
for (uint16_t i = 0; i < 6; i++) {// reset variables
motorPorts[i]->dmaDoneReading = false;
motorPorts[i]->timeout = 0;
motorPorts[i]->motorServiced = false;
};

// send read command to 1 motor on each port
uint8_t numMotorsRequested = 0;
for (uint8_t i = 1; i < 6; i ++) {
for (uint8_t i = 0; i < 6; i ++) {
MotorPort *p = motorPorts[i];
uint8_t currMotor = p->currReadMotor;
uint8_t motorId = p->motorIds[currMotor];
Expand All @@ -142,7 +142,6 @@ void read_motors(uint8_t *rxBuf) {
HAL_UART_Receive_DMA(p->huart, p->rxBuffer, p->rxPacketLen);
read_motor_present_position_p2(p, motorId);
}
p->currReadMotor = (currMotor + 1) % p->numMotors;
p->timeout = HAL_GetTick();
numMotorsRequested++; // keep track of how many motors we are reading
}
Expand Down Expand Up @@ -173,12 +172,14 @@ void read_motors(uint8_t *rxBuf) {
p->dmaDoneReading = false;
numMotorsReceived++;
p->motorServiced = true;
p->currReadMotor = (p->currReadMotor + 1) % p->numMotors;
} else {
//timeout logic
if(HAL_GetTick() - p->timeout > 10) { // units in milliseconds
HAL_UART_DMAStop(p->huart);
numMotorsReceived++; // unsuccesful but we still count as received
p->motorServiced = true;
p->currReadMotor = (p->currReadMotor + 1) % p->numMotors;
}
}
}
Expand Down

0 comments on commit 5509c07

Please sign in to comment.