Shop OBEX P1 Docs P2 Docs Learn Events
Parallax Laser Range Finder — Parallax Forums

Parallax Laser Range Finder

tashworthtashworth Posts: 1
edited 2014-02-24 08:15 in Accessories
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:
#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

  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-01-25 11:49
    I was hoping someone who knows more about this than I do would answer. Maybe this bump will help this thread get noticed.

    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.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2014-01-27 08:41
    Duane is right...sometimes we intend to reply to a thread and it gets forgotten for some reason. This pushed it back into my view again.

    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?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2014-02-10 09:04
    Bob, thanks for the follow-up. I didn't notice the mbed.h in the source code until you replied and I wondered what I missed in the original message. While I am not familiar with that MCU, storing a linear block of data should be pretty straight forward if you have the available memory.
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2014-02-21 21:14
    @ Chris Savage

    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.


  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2014-02-24 08:15
    For 2 and 3 dimensional arrays I admit you often have to think ahead about how things will be arranged. In this case I was thinking the data could be stored in a single array and could be formatted on output or by the device that will be displaying the information. At that point a simple subroutine could use a some math to grab each scan line and display it. It really depends on the display driver/code being used.

    @Bob - I'm sure there are some examples out there on the web. A search sounds like a good idea. :thumb:
Sign In or Register to comment.