Author Topic: Found a problem in Color Detection Code  (Read 3019 times)

0 Members and 1 Guest are viewing this topic.

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Found a problem in Color Detection Code
« on: March 09, 2008, 06:24:01 PM »
In the color recognition tutorial of admins ( which I used on my 3 in 1 bot) , I saw this code

where 108 is the reading taken
95 is the number for gray
112 is the number for white

Code: [Select]
now using our numbers:
grey floor = (108 - 95)/95 * 100 = 13.7% different
white line = (108 - 112)/112 * 100= 3.6% different

compare: white line < grey floor
therefore the sensor sees a white line

This pseudo code will not work on PICBASIC :
(108 - 112)/112 * 100= 3.6% different

Because 108-112 will give you a negative number ( which is unusable )
and when you divide by 112, you would get a number less than one ( also unusable)

So to fix that , I did this pseudo code
Code: [Select]
If reading < 112 then  (112-reading) *100 / 112
If reading > 112 then (reading - 112) *100 / 112

112-reading gets rid of any possibility for negative numbers and by doing *100 first , instead of /112 first, that gets rid of numbers less than one.


Do all microcontrollers have an inability to deal with negative numbers and numbers less than 1?

Just thought I'd share,
Eric

 

Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline frank26080115

  • Supreme Robot
  • *****
  • Posts: 322
  • Helpful? 2
Re: Found a problem in Color Detection Code
« Reply #1 on: March 09, 2008, 07:01:51 PM »
Stop using PIC BASIC, give BoostC a try, that way you can use signed chars and integers.
http://www.sourceboost.com/
I was so happy with it, I actually paid for the no-limit version. It was still $30 cheaper than PIC BASIC

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Found a problem in Color Detection Code
« Reply #2 on: March 09, 2008, 07:04:56 PM »
Stop using PIC BASIC, give BoostC a try, that way you can use signed chars and integers.
http://www.sourceboost.com/
I was so happy with it, I actually paid for the no-limit version. It was still $30 cheaper than PIC BASIC

I'll give it a try

but are there any books out there explaining how to use  BoostC?


Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Found a problem in Color Detection Code
« Reply #3 on: March 09, 2008, 09:04:18 PM »
I got a license for the Hitech PICC compiler  from a friend , so i'll give that a shot


there seems to be a lot of samples for that compiler, so that's always good

which PIC chip do you prefer frank?
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline frank26080115

  • Supreme Robot
  • *****
  • Posts: 322
  • Helpful? 2
Re: Found a problem in Color Detection Code
« Reply #4 on: March 09, 2008, 09:56:44 PM »
Stop using PIC BASIC, give BoostC a try, that way you can use signed chars and integers.
http://www.sourceboost.com/
I was so happy with it, I actually paid for the no-limit version. It was still $30 cheaper than PIC BASIC

I'll give it a try

but are there any books out there explaining how to use  BoostC?




BoostC was actually my first C language, the help file PDF in there explained absolutely everything.

I got a license for the Hitech PICC compiler  from a friend , so i'll give that a shot


there seems to be a lot of samples for that compiler, so that's always good

which PIC chip do you prefer frank?

Depends on what I need to use, but the PIC16F690 is good for experimenting because it packs a lot of features (4 timers etc) into a small package, good for learning.

Other than that, it really depends on what you need to do.

But hey, what the hell, they're free anyways!

 


Get Your Ad Here