Parallax Laser Range Finder
tashworth
Posts: 1
Hello! Forgive me, I am an amateur programmer. I have successfully written code to (using mbed micro-controller) to send an ASCI character to the Laser Range Finder (LRF) and have it return and display the distance measured. One of the cool things about this module is that it can also return an image if you send it the particular ASCI character, "G" in this case. I am having trouble figuring out how to store each byte received in a 2D char array for future image processing. Any help would be highly appreciated. Here is what the documentation says about this feature: ("G" refers to the ASCI character sent to the LRF)
G: Capture & send single frame (8 bits/pixel grayscale @ 160x128)
Capture a 160x128 resolution grayscale image with the LRF Module’s camera and return the data in a
binary format.
The data is sent MSB first, one byte per pixel, starting at the upper-left pixel location (0,0), moving left to
right, top to bottom across the frame, and ending at the lower-right pixel location (160,128). Each byte
corresponds to the brightness value of a single pixel where 0x00 is black and 0xFF is white.
A total of 20,480 bytes of binary data is sent. An ASCII footer (“END”) is then attached to the end of the
binary data stream to assist in identifying the end of frame.
Here is my code:
G: Capture & send single frame (8 bits/pixel grayscale @ 160x128)
Capture a 160x128 resolution grayscale image with the LRF Module’s camera and return the data in a
binary format.
The data is sent MSB first, one byte per pixel, starting at the upper-left pixel location (0,0), moving left to
right, top to bottom across the frame, and ending at the lower-right pixel location (160,128). Each byte
corresponds to the brightness value of a single pixel where 0x00 is black and 0xFF is white.
A total of 20,480 bytes of binary data is sent. An ASCII footer (“END”) is then attached to the end of the
binary data stream to assist in identifying the end of frame.
Here is my code:
#include "mbed.h" //Demo program for the Parallax Laser Range Finder DigitalOut myled(LED1); Serial pc(USBTX, USBRX); Serial lrf(p9,p10); int main() { char image[127][159]; // size of image 160Wx128H int row=0; int col=0; //Print prompt pc.printf("\f\nImage Processing Test\n\r"); //Delay for lrf power on startup wait(2.5); lrf.baud(115200); // lrf autobaud setup do { lrf.putc('U'); pc.putc('.'); wait(.2); if (lrf.readable()) lrfchar = lrf.getc(); } while (lrfchar != ':'); pc.printf("\n\r"); // clear out any extra characters - just in case while (lrf.readable()) { lrfchar = lrf.getc(); } lrf.putc('E'); //Light/focus adjustment //wait(.5); pc.printf("color balance done\n"); //store pixels in an array lrf.putc('G'); //Get Grey Scale Image for(row=0; row<128; row++){ for(col=0; col<160; col++){ image[row][col] = lrf.getc(); } col = 0; } myled=0; }
Comments
I've only used the range data coming from the LRF. I haven't tried to capture an image with it yet. Using the LRF to capture an image is on my todo list and I hope to get to this in the coming week.
I hope you keep us updated on any progress and I'll post again if I learn enough to help.
Since the data is essentially coming in as a long string of bytes you should be able to just store it that way as well, but I guess the microcontroller you're using may determine the place you store it. Which MCU are you using to talk to the LRF?
https://mbed.org/platforms/mbed-LPC1768/
http://en.wikipedia.org/wiki/Mbed_microcontroller
re: storing a linear block of data should be pretty straight forward if you have the available memory.
I've programed the Mbed for a few projects using C++ . Memory shouldn't be a problem. Maybe he just needs to search for C++ code that can do 2D char array.
@Bob - I'm sure there are some examples out there on the web. A search sounds like a good idea. :thumb: