Charles Jenkinson
New Member
Hi all,
Thanks so much for your help and advice.
I am building a system for a Solar Car challenge I volunteer for. We are crossing the Nullarbor Plain in Australia in December this year in a solar car built by high school students as a part of a Gifted and Talented Academic Program. This is my second crossing, and we are hoping to break the last record of 747km we set in 2011.
To make our convoy procedure safer, I am designing and building a system to determine the distance between the lead vehicle in our convoy, and the bus which provides close escort to the solar car (and the students we put on bicycles in a relay, to make sure they are worn out by the time we reach our camp sites!). The lead vehicle can sometimes travel up to 4 or 5 km ahead of the main convoy to ensure the road ahead is clear - information is provided by radio back to the bus, so we are able to safely negotiate the sometimes 75 metre long road trains that scream down the highway at 100 km/h. (Yes, we are nuts!)
The hardware interface of the design is relatively problem-free (I think). I have two 08M2 chips, each connected to a GPS module and XBee 09P unit. In essence, the lead vehicle's 08M2 receives an NMEA package from the GPS chip, teases out the GPRMC sentence, and sends this via XBee to the module in the bus. The XBee in the bus receives this sentence, and its own GPRMC sentence from its GPS module, and sends these via serial to a Raspberry Pi. I have written a program in C which then extracts the information, and determines the distance between the vehicles, prior to displaying this on a screen.
So far, so good. I have etched a circuit board for the lead vehicle, which sends its NMEA data (renamed with GPLDV, for LeaD Vehicle) each second, as evidenced by its flashing status LED, and the ability to receive this to Minicom with an XBee USB Adapter.
Now for my problem:
I can do this, but currently can only have the bus unit output both sentences (GPLDV and GPBUS - no prizes for guessing how I made up that tag!) every TWO seconds - as I say, this is a first world problem, but is something I wish to understand more fully.
Plugging the output into the Raspberry Pi's GPIO pins also does not capture output reliably, though this is no different when I connect a GPS module - both done through a 4.7K/10K voltage divider. Using the Picaxe programming cable is fine - 100% accurate data so far.
All baud rates are 9600 (except the USB cable to raspberry pi, which runs at 19200, as the picaxes are running at 16MHz.
My code immediately follows.
I think that the problem lies in the bus unit - it tries to fill all of the scratchpad memory with serial output from the Lead Vehicle module, and since there are more @bptrinc than items in the serial string, it waits for the next sentence to be transmitted, but then does not send this on.
I have tried three solutions that I can think of (tested on the Lead Vehicle and Bus side):
1) process each byte in scratchpad individually, testing for each character, by using a do while loop. This continues until it sees then next $ sign after the $GPRMC/$GPLDV, and the loop then exits. This resulted in a scrambled output, probably because the Picaxe isn't fast enough to process the serial whilst receiving.
2) use timeouts in a do-loop after $GPRMC/$GPLDV is received - this results in gobbledegook - I'm sure this is the same problem as before - the Picaxe is probably not fast enough to keep up with the serial stream at 9600
3) Cut down the number of @bptrinc in the received line - this has no impact.
Unfortunately this NMEA sentence has a variable length, so I can't only grab the bytes I need. I'm not sure of another way to stop immediately after the $GPRMC checksum.
I've thought of using HSerin, but can't see any advantage, since I think it is a problem of the Picaxe not being able to process the bytes as it is receiving them.
I could decrease the baud rate of the transmissions to 4800, and try again. This would require reprogramming/reconfiguring the GPS/XBee, and I'm sure there is a work-around somehow.
A kludge might be to pad out the sentence sent back to the bus with extra, "meaningless" bytes of information.
I am of course open to the suggestion that I may be totally off in my reasoning, and it may be something else much more simple/complex.
Ultimately, if we have a refresh rate of 2 seconds, this is not the end of the world, but I'd like to explore this (even if it is nothing more than an academic exercise).
I can post the Eagle schematics if this helps.
Many thanks, and my apologies for a long and rambling post.
Charles
Thanks so much for your help and advice.
I am building a system for a Solar Car challenge I volunteer for. We are crossing the Nullarbor Plain in Australia in December this year in a solar car built by high school students as a part of a Gifted and Talented Academic Program. This is my second crossing, and we are hoping to break the last record of 747km we set in 2011.
To make our convoy procedure safer, I am designing and building a system to determine the distance between the lead vehicle in our convoy, and the bus which provides close escort to the solar car (and the students we put on bicycles in a relay, to make sure they are worn out by the time we reach our camp sites!). The lead vehicle can sometimes travel up to 4 or 5 km ahead of the main convoy to ensure the road ahead is clear - information is provided by radio back to the bus, so we are able to safely negotiate the sometimes 75 metre long road trains that scream down the highway at 100 km/h. (Yes, we are nuts!)
The hardware interface of the design is relatively problem-free (I think). I have two 08M2 chips, each connected to a GPS module and XBee 09P unit. In essence, the lead vehicle's 08M2 receives an NMEA package from the GPS chip, teases out the GPRMC sentence, and sends this via XBee to the module in the bus. The XBee in the bus receives this sentence, and its own GPRMC sentence from its GPS module, and sends these via serial to a Raspberry Pi. I have written a program in C which then extracts the information, and determines the distance between the vehicles, prior to displaying this on a screen.
So far, so good. I have etched a circuit board for the lead vehicle, which sends its NMEA data (renamed with GPLDV, for LeaD Vehicle) each second, as evidenced by its flashing status LED, and the ability to receive this to Minicom with an XBee USB Adapter.
Now for my problem:
I can do this, but currently can only have the bus unit output both sentences (GPLDV and GPBUS - no prizes for guessing how I made up that tag!) every TWO seconds - as I say, this is a first world problem, but is something I wish to understand more fully.
Plugging the output into the Raspberry Pi's GPIO pins also does not capture output reliably, though this is no different when I connect a GPS module - both done through a 4.7K/10K voltage divider. Using the Picaxe programming cable is fine - 100% accurate data so far.
All baud rates are 9600 (except the USB cable to raspberry pi, which runs at 19200, as the picaxes are running at 16MHz.
My code immediately follows.
I think that the problem lies in the bus unit - it tries to fill all of the scratchpad memory with serial output from the Lead Vehicle module, and since there are more @bptrinc than items in the serial string, it waits for the next sentence to be transmitted, but then does not send this on.
I have tried three solutions that I can think of (tested on the Lead Vehicle and Bus side):
1) process each byte in scratchpad individually, testing for each character, by using a do while loop. This continues until it sees then next $ sign after the $GPRMC/$GPLDV, and the loop then exits. This resulted in a scrambled output, probably because the Picaxe isn't fast enough to process the serial whilst receiving.
2) use timeouts in a do-loop after $GPRMC/$GPLDV is received - this results in gobbledegook - I'm sure this is the same problem as before - the Picaxe is probably not fast enough to keep up with the serial stream at 9600
3) Cut down the number of @bptrinc in the received line - this has no impact.
Unfortunately this NMEA sentence has a variable length, so I can't only grab the bytes I need. I'm not sure of another way to stop immediately after the $GPRMC checksum.
I've thought of using HSerin, but can't see any advantage, since I think it is a problem of the Picaxe not being able to process the bytes as it is receiving them.
I could decrease the baud rate of the transmissions to 4800, and try again. This would require reprogramming/reconfiguring the GPS/XBee, and I'm sure there is a work-around somehow.
A kludge might be to pad out the sentence sent back to the bus with extra, "meaningless" bytes of information.
I am of course open to the suggestion that I may be totally off in my reasoning, and it may be something else much more simple/complex.
Ultimately, if we have a refresh rate of 2 seconds, this is not the end of the world, but I'd like to explore this (even if it is nothing more than an academic exercise).
I can post the Eagle schematics if this helps.
Many thanks, and my apologies for a long and rambling post.
Charles