Thanks Amanda!
I’m quite satisfied with the progress so far and I will post an update in the “share your project” section shortly.
I still have a small issue with the encoders where I noticed that when I increase the frequency at which I read the I2C struct data from the Raspberry Pi (say from 20/s to 50/s), I seem to be loosing some counts, i.e. the robot moves faster for the same speed command (the motor speeds are regulated with PID controllers using feedback from the encoders) and farther for the same number of counts.
I believe it has to do with the fact that, to avoid overflow of the encoders count variables on the A-Star, I reset these values every time the python code on the Raspberry Pi reads the encoder counts from the I2C struct data.
I plan on trying a few things to identify the cause of the issue:
1 - Remove the encoder reset (not a solution but can help to see if this is the cause)
2 - Disable interrupts around the portion of the A-Star code were I write the encoder count variables to the slave buffer and where I reset the encoder counts.
Any other idea? Thanks!
Below is the method of my Encoders class that reads the encoders (python, Raspberry Pi end):
def readCounts(self):
countLeft, countRight = self.aStar.read_encoders()
self.aStar.reset_encoders()
self.countLeft += self.countSignLeft * countLeft
self.countRight += self.countSignRight * countRight
return self.countLeft, self.countRight
and the corresponding function in the AStar class (python, Raspberry Pi end):
def read_encoders(self):
return self.read_unpack(25, 4, "hh")
def reset_encoders(self):
self.write_pack(24, 'B', 1)
Below is the portion of the A-Star code where the encoder values are written to the struct and then reset:
// Read encoders
slave.buffer.encoderLCount = encoderLeftCount;
slave.buffer.encoderRCount = encoderRightCount;
if (slave.buffer.resetEncoders)
{
slave.buffer.resetEncoders = 0;
encoderLeftCount = 0;
encoderRightCount = 0;
}
Full code is available at https://github.com/DrGFreeman/RasPiBot202