To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 3341
3340  |  3342
Subject: 
NQC Barcode program
Newsgroups: 
lugnet.robotics
Date: 
Sat, 30 Jan 1999 23:14:23 GMT
Original-From: 
Sam Edwards <sam.is@SAYNOTOSPAMhome.com>
Viewed: 
862 times
  
The following is a program someone made on the mindstorms page. There is an
error on line 13 but I can't figure it out. I'm not all that experienced so
it may be something simple I don't know. Any way, have a look:

//This program will decode a "3 of 9" barcode as scanned by the
// accompanying NQC program for the Lego Mindstorms RCX.
//
// The "3 of 9" barcode is fairly simple. Each encoded character is
// represented by nine bars. Bars alternate between black and white,
// so a nine bar sequence both begins and ends with a black bar. Three
// of these nine bars will be "thick", and six will be "thin". Nine bar
// sections are separated by a single thin white bar.
//

// samples greater than or equal to this are considered to be white
$white = 49;

// samples less than or equal to this are considered to be black
$black = 44;

// how many samples beyond the threshold are required for a thin line
$thin = 1;

// how many samples beyond the threshold are required for a thick line
$thick = 3;

// 3 of 9 character map
// Only digits are handled right now -- I'm too lazy to type the whole
alphabet.
%map = (
  "000110100" => "0",
  "100100001" => "1",
  "001100001" => "2",
  "101100000" => "3",
  "000110001" => "4",
  "100110000" => "5",
  "001110000" => "6",
  "000100101" => "7",
  "100100100" => "8",
  "001100100" => "9",
  "010010100" => "*",
);

// look for first black sample
while (<>) { last if ($_ <= $black); }

// indicate one black sample so far
$last = 0;
$width = 1;

while (<>) {

// only consider the sample if it is beyond the threshold
  if ($_ >= $white) { $value = 1; }
  elsif ($_ <= $black) { $value = 0; }
  else { next; }

  if ($value == $last) {
// if the new sample is the same as the last one, increment counter
    $width++;
  } else {
// otherwise, determine if bar was thick or thin and reset counters
    if ($width >= $thick) { $code .= "1"; }
    elsif ($width >= $thin) { $code .= "0"; }
    $last = $value;
    $width = 1;
  }

}

// decode the string
while ($code) {
  print $map{substr($code,0,9)};
  substr($code,0,10) = "";
}

print "\n";

----------------------------------------------------------------------------
---------------
                             Sam Edwards

"On the keyboard of life, always keep one finger on the escape key."

--
Did you check the web site first?: http://www.crynwr.com/lego-robotics



Message has 1 Reply:
  Re: NQC Barcode program
 
(...) That someone would be me. There's no error -- you just have to use the right language. :) Anyway, this is not Lego RIS code (or whatever they call it), and it's not NQC code. It's Perl. Sadly, the Lego site only allows you to upload one (...) (26 years ago, 31-Jan-99, to lugnet.robotics)

2 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR