BrickPi.h BrickPiRx Error: -5

Hi,

I am building the brickpi-raspberry nodejs module as an API to the BrickPi. My module wraps the C library provided by Dexter. As I run my code, everything works usually fine, however, from time to time, the encoder values for the motors will be all wrong for a cycle, breaking all the downstream logic.

I’ve turned on the DEBUG flag in BrickPi.h, and I can see a couple of reties and -2 errors. These are not the issue. It’s when I get a -5 error that the encoders will be all wrong. After the -5, I assume that their is a successful retry (i.e. BrickPiUpdateValues does not return -1) however, Like I said, the encoder values are all wrong.

WHat am I missing here?

Here is a trace:

Three motors and their positions:

starting position (FP AP): -6347:6825:0
starting position (FP AP): -6275:6761:0
starting position (FP AP): -6207:6700:0
starting position (FP AP): -6140:6640:0
starting position (FP AP): -6073:6579:0
BrickPiRx error: -6
retying
BrickPiRx error: -4
retying
starting position (FP AP): -6005:6519:0
Stopping in _moved a: fore
BrickPiRx error: -5
retying
starting position (FP AP): 23568:6455:0
Stopping in _moved b: arm
starting position (FP AP): -5861:-23048:-1
starting position (FP AP): -5815:6325:0
starting position (FP AP): -5794:6282:0

Hmm, not sure what the problem is immediately. However, the -5 return indicates that something was corrupted with the messages sent back and forth between the BrickPi and the Raspberry Pi. “-5” means the checksum was either not calculated properly, or it was not found in the correct position in the returned array.

So this return is very similar to the “-2” response in the sense that something erred in the transmission between the two, it’s just more specific ( I think we decided to add this specific response because we were testing checksum algorthims), but gives you a little more granularity on what might be going wrong.

-6 and -4 returns are very similar: they’re also indicating that something went wrong with the transmission.

Does this help answer the question, or am I missing your point?

This is the part that’s really the problem right?

retying
starting position (FP AP): 23568:6455:0
Stopping in _moved b: arm

The fact that the first encoder is jumping around and suddenly gives you wrong values, is that what you’re seeing?

I was also getting many -4, -5 and -6 errors. In my case I believe it is related to the power supply. In my setup I am powering the RPI from its own 5V 2A power supply.

The BrickPi board was powered by a 9V 0.6A power supply. I am using the NXT motors, which can draw up to two amps, e.g. see:

http://www.philohome.com/motors/motorcomp.htm

So it would appear that 0.6A is not enough power. I found another wall-wart in my collection that puts out 1A – slightly better. The number of errors decreased significantly, no more -4 and -5 errors, but I still get quite a few -6 errors. I’ve got another power supply on order capable of 6A. Hopefully that will address the problem.

Hey tophwedg, curious about why you’re using such low amperage supplies? The motors, especially when starting, stopping, and changing directions can draw an amp or more. Often wall supplies that are rated for lower amperage won’t keep up; even if they’re 1A, they may not be able to supply that sort of draw instantly (as motors can demand).

Any way you can change to a battery?