Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite loops #10

Open
luca-byte opened this issue Jan 13, 2025 · 1 comment
Open

Infinite loops #10

luca-byte opened this issue Jan 13, 2025 · 1 comment

Comments

@luca-byte
Copy link
Member

Problem

When the hardware is not properly connected or is malfunctioning, the code gets stuck in many infinite loops (notably in SmartMotor#calibrate(). This makes the issue undiscoverable using Serial communication and makes the upload of new firmware problematic (open/close port).

Proposed Solution

For each infinite loops provide a certain termination condition or a timeout. Use the return values to instruct the main loop behavior, which should signal malfunction either on the serial port or via can apposite messages.

@luca-byte
Copy link
Member Author

List of while clauses.

include\quadrature_encoder.pio.h:
  104  {
  105: 	while (pio_sm_is_rx_fifo_empty(pio, sm));
  106  	return pio->rxf[sm];

lib\Can\src\mcp2515.cpp:
  180      bool modeMatch = false;
  181:     while (millis() < endTime) {
  182          uint8_t newmode = readRegister(MCP_CANSTAT);

lib\DynamixelSerial\src\DynamixelSerial.cpp:
   4    serialPort->write(b);
   5:   while (serialPort->available() < 1);
   6    serialPort->read();

  10    int tc = 0;
  11:   while ((serialPort->available() < n) && (tc < AX_TIME_OUT)) {
  12      tc++;

  39    serialPort->write(out, n);
  40:   while (serialPort->available() < n);
  41    for(int i = 0; i < n; i++) serialPort->read();

  48  
  49:   while (serialPort->available() > 0) {
  50      byte in = serialPort->read();

  67  
  68:   while (serialPort->available() > 0) {
  69      byte in = serialPort->read();

  86    
  87:   while (serialPort->available() > 0) {
  88      byte in = serialPort->read();

lib\SmartMotor\src\SmartMotor.cpp:

  84      motor.write(PWM_MAX_VALUE);
  85:     while(getSpeed() < th) delay(DT_ENC);
  86      int t_high = millis();

  88      motor.write(0);
  89:     while(getSpeed() > tl) delay(DT_ENC);
  90      int t_low = millis();

lib\WebManagement\src\WebManagement.cpp:

  166    if (file) {
  167:     while (file.available()) out += (char) file.read();
  168      file.close();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant