Gopigo.py - commands sometimes are getting ignored

I’m seeing an intermittent problem where the “stop()” command is being ignored. Usually this happens for both motors but sometimes one motor will stop but the other one will continue to run.

Hey,
Can you upload the code as a .txt file. It did not upload the last time because it was a .py file.

-Karan

attached

I think this issue is caused by a bug in the gopigo firmware fw_ver_13. The i2c ISR (receiveData) will overwrite the previous command whenever it gets a new one. This means you will drop commands if you issue a bunch of them back to back.

You may want to consider a dbl buffering scheme e.g.


volatile int cmd[5],index=0,flag=0,bytes_to_send=0; //I2C Message variables
volatile int cmdbuffer[33], i2c_overrun_errors=0; // dbl buffer incoming I2C

// get i2c cmd from buffer
// loads cmd[] with next command if available
// returns true if new cmd[] was extracted from buffer
// call this once at the top of the polling loop
bool get_i2c_cmd()
{
ret = false;
if(index > 3)
{
ret = true;
for(int i=0;i<4;i++) cmd[i]=cmdbuffer[i];
nointerrupts(); // disable interrupts while shifting the buffer contents
for(int i=4;i<index;i++) cmdbuffer[i-4]=cmdbuffer[i];
index=-4;
interrupts();
}
return ret;
}

// —revised—
//Receive commands via I2C
void receiveData(int byteCount)
{
if(byteCount+index < 33)
{
while(Wire.available()) cmdbuffer[index++] = Wire.read();
}
else
{
// oops - have overrun
i2c_overrun_errors++; // for now just count them
// may want to add a flag to status_r for this error
// may want new cmd to return i2c_overrun_errors
index=0; // reset whole buffer
while(Wire.available())Wire.read(); // drain i2c
}
if(timout_f)last_t=millis(); //comm T/O refresh
}

I’m having the same issue. For example when running the Python led_blink.py example sometimes only one LED will react.

Looking forward to a firmware upgrade… :slight_smile:

I learned from other posts on this forum that I should add a time.delay(.1) after each GoPiGo command, to prevent commands from being ignored.

I learned from other posts on this forum that I should add a time.delay(.1) after each GoPiGo command, to prevent commands from being ignored.

Ahhh… thanks for this. Still, it looks like the actual problem still needs to be fixed…

We really appreciate the feedback and will try to update the firmware in the near future. Thanks folks!