EmbeddedRelated.com
Forums

newby! questions BX + Sharp Sensor

Started by CHANCE June 17, 2005
Hi

my friend T. Andley gave me a reference to this site re: Bx-24. Him
and I do hacks with the robosapien robot.

I just recently purchased a BX-24 Dev kit, along with Robodyssey Hack-
A-Toy(Robosapien) kit which feature the BX chip and a "portable"
board to apply to Robosapien's back

picture's and my work can be found at -
http://pruim037.proboards23.com/index.cgi?
board=technicalmb&action=display&thread18684622

I have a few questions, I havnt 100% set up my RS to the chip yet,
since I am still developing the basic skills for this chip, so below
I have posted a Program that has being modified.

basically this program communicates with the Sharp G2D12 (spelling)
Sensor and also the RED/GREEN LED on the BX-Board

I am currently using the To Far/To Close/Just right example, along
with flashing LED to tell me wheather it is to far or just right. I
also added a Cst(getADC(13)) at the end of each command so it could
give me the value, however I would like to get this value in a
CM/INCH format

how about would I add a math calculation to the code? or any
reference's that have this.

do you divide the value by 8, and if so how would that be, I have
posted code below

thanks
Option Explicit
Dim value as Integer
Public Sub Main()
Do
Call SensorIn
Loop
End Sub

'************************************************

Sub SensorIN()
Do
value=GetADC(13) ' gets value from sensor
if value > 450 Then
Call Toclose
Sleep(0.3)
End if
If value <150 Then
Call Tofar
Sleep(0.3)
end if

sleep (0.3)
Debug.print "Just Right" ;Cst(getADC(13)) ; "cm"
Call Putpin (25,0) 'red light on
Call Putpin (26,0)'green light on
Delay (0.5)
Call Putpin (25,1) 'red light off
Call Putpin (26,1) 'green light on
Loop
End Sub '*****************************************************

Sub Tofar()
Do
Debug.print "To Far" ;Cst(getADC(13)) ; "cm"
Call Putpin (25,0) 'red light on
Delay (0.5)
Call Putpin(25,1)
value= GetADC(13) ' gets value from sensor
if value > 150 Then
Call SensorIn
Sleep(0.3)
End If
Sleep (0.3)
Loop
End Sub '*******************************************************

Sub Toclose()
Do
debug.print "To Close" ;Cst(getADC(13)) ; "cm"
Call Putpin (26,0) 'green light on
Delay (0.5)
Call Putpin (26,1) 'green light off
value = GetADC(13) ' gets value from sensor
if value <450 Then
Call SensorIn
End If
Sleep(0.3)
Loop
End Sub Chance 'kNiTsU" Brown (knitsu@knit...

my RS site : http://www.evosapien.com/robosapien-hack/knitsu/


You would be better off using the float version of getADC, then divide
by 2.54 to convert to inches:
something like this:
dim value as single 'cm
dim value_inches as single 'inches

value= GetADC(13) ' gets value from sensor in cm
value_inches = value/2.54 'inches
debug.print Distance = cst(value)& "cm/ "& cst(value_inches)"& "inches" CHANCE wrote:

> Hi
>
> my friend T. Andley gave me a reference to this site re: Bx-24. Him
> and I do hacks with the robosapien robot.
>
> I just recently purchased a BX-24 Dev kit, along with Robodyssey Hack-
> A-Toy(Robosapien) kit which feature the BX chip and a "portable"
> board to apply to Robosapien's back
>
> picture's and my work can be found at -
> http://pruim037.proboards23.com/index.cgi?
> board=technicalmb&action=display&thread18684622
>
> I have a few questions, I havnt 100% set up my RS to the chip yet,
> since I am still developing the basic skills for this chip, so below
> I have posted a Program that has being modified.
>
> basically this program communicates with the Sharp G2D12 (spelling)
> Sensor and also the RED/GREEN LED on the BX-Board
>
> I am currently using the To Far/To Close/Just right example, along
> with flashing LED to tell me wheather it is to far or just right. I
> also added a Cst(getADC(13)) at the end of each command so it could
> give me the value, however I would like to get this value in a
> CM/INCH format
>
> how about would I add a math calculation to the code? or any
> reference's that have this.
>
> do you divide the value by 8, and if so how would that be, I have
> posted code below
>
> thanks >
> Option Explicit
> Dim value as Integer
> Public Sub Main()
> Do
> Call SensorIn
> Loop
> End Sub
>
> '************************************************
>
> Sub SensorIN()
> Do
> value=GetADC(13) ' gets value from sensor
> if value > 450 Then
> Call Toclose
> Sleep(0.3)
> End if
> If value <150 Then
> Call Tofar
> Sleep(0.3)
> end if
>
> sleep (0.3)
> Debug.print "Just Right" ;Cst(getADC(13)) ; "cm"
> Call Putpin (25,0) 'red light on
> Call Putpin (26,0)'green light on
> Delay (0.5)
> Call Putpin (25,1) 'red light off
> Call Putpin (26,1) 'green light on
> Loop
> End Sub > '*****************************************************
>
> Sub Tofar()
> Do
> Debug.print "To Far" ;Cst(getADC(13)) ; "cm"
> Call Putpin (25,0) 'red light on
> Delay (0.5)
> Call Putpin(25,1)
> value= GetADC(13) ' gets value from sensor
> if value > 150 Then
> Call SensorIn
> Sleep(0.3)
> End If
> Sleep (0.3)
> Loop
> End Sub > '*******************************************************
>
> Sub Toclose()
> Do
> debug.print "To Close" ;Cst(getADC(13)) ; "cm"
> Call Putpin (26,0) 'green light on
> Delay (0.5)
> Call Putpin (26,1) 'green light off
> value = GetADC(13) ' gets value from sensor
> if value <450 Then
> Call SensorIn
> End If
> Sleep(0.3)
> Loop
> End Sub > Chance 'kNiTsU" Brown (knitsu@knit...
>
> my RS site : http://www.evosapien.com/robosapien-hack/knitsu/ >
>
> *>.




Chance/Knitsu, welcome aboard ;-)

I already responded on this topic in the RS TK forum.

- Tom

--- In basicx@basi..., "CHANCE" <chancebrown2003@y...> wrote:
> Hi
>
> my friend T. Andley gave me a reference to this site re: Bx-24.
Him
> and I do hacks with the robosapien robot.
>
> I just recently purchased a BX-24 Dev kit, along with Robodyssey
Hack-
> A-Toy(Robosapien) kit which feature the BX chip and a "portable"
> board to apply to Robosapien's back
>
> picture's and my work can be found at -
> http://pruim037.proboards23.com/index.cgi?
> board=technicalmb&action=display&thread18684622
>
> I have a few questions, I havnt 100% set up my RS to the chip yet,
> since I am still developing the basic skills for this chip, so
below
> I have posted a Program that has being modified.
>
> basically this program communicates with the Sharp G2D12 (spelling)
> Sensor and also the RED/GREEN LED on the BX-Board
>
> I am currently using the To Far/To Close/Just right example, along
> with flashing LED to tell me wheather it is to far or just right.
I
> also added a Cst(getADC(13)) at the end of each command so it could
> give me the value, however I would like to get this value in a
> CM/INCH format
>
> how about would I add a math calculation to the code? or any
> reference's that have this.
>
> do you divide the value by 8, and if so how would that be, I have
> posted code below
>
> thanks >
> Option Explicit
> Dim value as Integer
> Public Sub Main()
> Do
> Call SensorIn
> Loop
> End Sub
>
> '************************************************
>
> Sub SensorIN()
> Do
> value=GetADC(13) ' gets value from sensor
> if value > 450 Then
> Call Toclose
> Sleep(0.3)
> End if
> If value <150 Then
> Call Tofar
> Sleep(0.3)
> end if
>
> sleep (0.3)
> Debug.print "Just Right" ;Cst(getADC(13)) ; "cm"
> Call Putpin (25,0) 'red light on
> Call Putpin (26,0)'green light on
> Delay (0.5)
> Call Putpin (25,1) 'red light off
> Call Putpin (26,1) 'green light on
> Loop
> End Sub > '*****************************************************
>
> Sub Tofar()
> Do
> Debug.print "To Far" ;Cst(getADC(13)) ; "cm"
> Call Putpin (25,0) 'red light on
> Delay (0.5)
> Call Putpin(25,1)
> value= GetADC(13) ' gets value from sensor
> if value > 150 Then
> Call SensorIn
> Sleep(0.3)
> End If
> Sleep (0.3)
> Loop
> End Sub > '*******************************************************
>
> Sub Toclose()
> Do
> debug.print "To Close" ;Cst(getADC(13)) ; "cm"
> Call Putpin (26,0) 'green light on
> Delay (0.5)
> Call Putpin (26,1) 'green light off
> value = GetADC(13) ' gets value from sensor
> if value <450 Then
> Call SensorIn
> End If
> Sleep(0.3)
> Loop
> End Sub > Chance 'kNiTsU" Brown (knitsu@g...
>
> my RS site : http://www.evosapien.com/robosapien-hack/knitsu/


Hi Chance,

If you purchased your hack-a-toy from Robodyssey I assume you are
using the Sharp GP2D12 sensor. This is a non-linear device so you
can't simply divide or multiply by some constant to convert the
digital output to distance in centimeters, say. One way to come up
with a conversion equation is to set the sensor up so it points
(perfectly level) toward a wall and record digital readings and
their corresponding actual distances. Then enter your data into
Excel, plot it, and add a trendline. The equation of the trendline
will allow you to convert the digital sensor output to a distance.
Of course, you'll need a meterstick or tape measure. Take your time
making the measurements carefully.

OR, you can just use the results from my calibration, which should
closely agree with your sensor. Namely,

Range = (4187.8 / IRValue)^1.1060

where IRValue is the digital (integer) value returned by the IR
sensor. This fit is accurate to less than 2% over most of the
sensor's range, and is especially well behaved between 10 and 70cm:
+/- 1cm. I'm writing a book now about BasicX programming, but I'll
go ahead and PDF a couple of pages and post them for you on on my
site: www.basicxandrobotics.com. The site was just launched, so
it's not very polished.

I also have a fairly popular Excel tutorial that you might like. It
can be found on several sites including:

http://phoenix.phys.clemson.edu/tutorials/excel/
and
www.basicxandrobotics.com

About your code, you should use the "Call" keyword to invoke the
Delay and Sleep procedures. That is, type "Call Delay(1.0)" rather
than "Delay(1.0)". (Often it works without it, but sometimes not.
Better to head-off any intermittent problems early!) Also, i
usually have better luck using the Delay procedure and the Sleep
procedure.

hope this helps.

--chris

--- In basicx@basi..., "CHANCE" <chancebrown2003@y...> wrote:
> also added a Cst(getADC(13)) at the end of each command so it
could
> give me the value, however I would like to get this value in a
> CM/INCH format
>
> how about would I add a math calculation to the code? or any
> reference's that have this.



chris_odom_georgeschool wrote:

>
> I'm writing a book now about BasicX programming, but I'll
> go ahead and PDF a couple of pages and post them for you on on my
> site: www.basicxandrobotics.com. The site was just launched, so
> it's not very polished.

Great!! It's always great to see more material about BasicX. I am a big
fan of the platform as I think NetMedia made I lot of good design
choices both in hardware and software. I believe BasicX is technically
light-years ahead of Basic Stamp.

Thirteen of the chapters look like a good tutorial on using BasicX.
However I have noticed that three of chapters are heavily geared toward
your company's products. Nothing wrong with that I guess but I think the
title of the book is misleading as it doesn't include anything on
steppers, DC motors, line detection and a myriad other "robot" topics. I
wouldn't consider this a complete treatise without some coverage of
these other areas.

If you need reviewers I'm sure you could get a few volunteers from this
group. Try the usual suspects T, T, D, T & M.

My 2 cents.
Mike



Hey Mike,

I, too, think the BX-24 is they way to go. I was a rocket scientist
at Clemson University when my student Matt Vaughn (now at NASA) got
me hooked on the BX-24. (I was a long-time programmer, but now I
could make my programs actually DO something without a EE degree.
It was glorious.)

I am a teacher at heart and, while I was having fun using the BX-24
in my own circuits, I realized the novice user was a long way away
from using it. I quit the rocket-science business and started
teaching high school physics in Newtown, Pennsylvania. Our first
class project was to build a payload and inertial switches that
would eventually fly into space onboard a Terrier-Orion rocket. At
lift-off, the switches were to power the microcontroller which would
then monitor the temperature and forces during the flight. The
payload and switches were all homemade by my students, but we had
intermittent problems with our motherboard. At this point, I
happened upon Robodyssey Systems who gave me their motherboard (the
RAMB) to use in the payload. (The switches, payload, and
motherboard worked perfectly. Now, if I could find the time to
publish that data!)

I soon learned that Robodyssey also sold robots for classroom use,
and I realized that this was the way to get the uninitiated into
robotics. All that was needed was a textbook. Based on my great
experiences with the NetMedia's BX-24 microcontroller and BasicX
language, and Robodyssey's educational robots, I set out to write an
introductory text for anyone wanting to get into robotics
programming without the gimmicks.

I am not affiliated with Robodyssey, but because my book is based in
large part on their equipment, they have agreed to handle the
distribution of my book.

I agree that to be a complete treatise I need to include other
advanced topics and I am already thinking about what Volume 2 will
look like. The book I've written is designed for classroom
instruction, so a stable and versatile platform is a must. My
research tells me that NetMedia and Robodyssey is the way to go.
I've designed the book to be a personal tutor that walks the
complete novice through BasicX programming and robotic applications
in a way that hopefully relieves apprehension and eliminates the
guesswork. The book is essentially 400 pages of fundamentals with
hundreds of Challenge Problems and Self Tests to motivate teachers
as well as the curious hobbyist. Moving is the easy part, knowing
where to go is the hard part. My hope is that my book builds the
foundations of complex computational skills that will give people
the ability to make their robots engage its enviroment not just
twitch in response to a stimuli.

Thanks for your two cents, Mike. Sorry my response was a
nickel's
worth.

chris

--- In basicx@basi..., Mike Perks <basicx@a...> wrote:
> chris_odom_georgeschool wrote:
> > I'm writing a book now about BasicX programming, but I'll
> > go ahead and PDF a couple of pages and post them for you on on my
> > site: www.basicxandrobotics.com. The site was just launched, so
> > it's not very polished.
>
> Great!! It's always great to see more material about BasicX. I am
a big
> fan of the platform as I think NetMedia made I lot of good design
> choices both in hardware and software. I believe BasicX is
technically
> light-years ahead of Basic Stamp.
>
> Thirteen of the chapters look like a good tutorial on using
BasicX.
> However I have noticed that three of chapters are heavily geared
toward
> your company's products. Nothing wrong with that I guess but I
think the
> title of the book is misleading as it doesn't include anything on
> steppers, DC motors, line detection and a myriad other "robot"
topics. I
> wouldn't consider this a complete treatise without some coverage
of
> these other areas.
>
> If you need reviewers I'm sure you could get a few volunteers from
this
> group. Try the usual suspects T, T, D, T & M.
>
> My 2 cents.
> Mike



chris_odom_georgeschool wrote:

> I am not affiliated with Robodyssey, but because my book is based in
> large part on their equipment, they have agreed to handle the
> distribution of my book.

That helps clear up a few misconceptions I had.

> The book I've written is designed for classroom
> instruction, so a stable and versatile platform is a must. My
> research tells me that NetMedia and Robodyssey is the way to go.

Now I understand the educational leaning of the book and your yahoo
username. Good job on writing a BasicX introductory book.

Mike



Both Thandley and Chris Odom have helped me out on this finding a
value in CM for the sensor

ange = (4187.8 / IRValue)^1.1060 which has worked great,I hope to add it to my Robosapien Autonmous
V3.0 withing the next few weeks so calculations look alot more
precise and give readings that are alot eaiser to understand.... Thanks :-)

--- In basicx@basi..., "tombhandley" <gr13tbs@c...> wrote:
> Chance/Knitsu, welcome aboard ;-)
>
> I already responded on this topic in the RS TK forum.
>
> - Tom
>
> --- In basicx@basi..., "CHANCE" <chancebrown2003@y...>
wrote:
> > Hi
> >
> > my friend T. Andley gave me a reference to this site re: Bx-24.
> Him
> > and I do hacks with the robosapien robot.
> >
> > I just recently purchased a BX-24 Dev kit, along with Robodyssey
> Hack-
> > A-Toy(Robosapien) kit which feature the BX chip and a "portable"
> > board to apply to Robosapien's back
> >
> > picture's and my work can be found at -
> > http://pruim037.proboards23.com/index.cgi?
> > board=technicalmb&action=display&thread18684622
> >
> > I have a few questions, I havnt 100% set up my RS to the chip
yet,
> > since I am still developing the basic skills for this chip, so
> below
> > I have posted a Program that has being modified.
> >
> > basically this program communicates with the Sharp G2D12
(spelling)
> > Sensor and also the RED/GREEN LED on the BX-Board
> >
> > I am currently using the To Far/To Close/Just right example,
along
> > with flashing LED to tell me wheather it is to far or just
right.
> I
> > also added a Cst(getADC(13)) at the end of each command so it
could
> > give me the value, however I would like to get this value in a
> > CM/INCH format
> >
> > how about would I add a math calculation to the code? or any
> > reference's that have this.
> >
> > do you divide the value by 8, and if so how would that be, I have
> > posted code below
> >
> > thanks
> >
> >
> >
> > Option Explicit
> > Dim value as Integer
> > Public Sub Main()
> > Do
> > Call SensorIn
> > Loop
> > End Sub
> >
> > '************************************************
> >
> > Sub SensorIN()
> > Do
> > value=GetADC(13) ' gets value from sensor
> > if value > 450 Then
> > Call Toclose
> > Sleep(0.3)
> > End if
> > If value <150 Then
> > Call Tofar
> > Sleep(0.3)
> > end if
> >
> > sleep (0.3)
> > Debug.print "Just Right" ;Cst(getADC(13)) ; "cm"
> > Call Putpin (25,0) 'red light on
> > Call Putpin (26,0)'green light on
> > Delay (0.5)
> > Call Putpin (25,1) 'red light off
> > Call Putpin (26,1) 'green light on
> > Loop
> > End Sub
> >
> >
> > '*****************************************************
> >
> > Sub Tofar()
> > Do
> > Debug.print "To Far" ;Cst(getADC(13)) ; "cm"
> > Call Putpin (25,0) 'red light on
> > Delay (0.5)
> > Call Putpin(25,1)
> > value= GetADC(13) ' gets value from sensor
> > if value > 150 Then
> > Call SensorIn
> > Sleep(0.3)
> > End If
> > Sleep (0.3)
> > Loop
> > End Sub
> >
> >
> > '*******************************************************
> >
> > Sub Toclose()
> > Do
> > debug.print "To Close" ;Cst(getADC(13)) ; "cm"
> > Call Putpin (26,0) 'green light on
> > Delay (0.5)
> > Call Putpin (26,1) 'green light off
> > value = GetADC(13) ' gets value from sensor
> > if value <450 Then
> > Call SensorIn
> > End If
> > Sleep(0.3)
> > Loop
> > End Sub
> >
> >
> > Chance 'kNiTsU" Brown (knitsu@g...
> >
> > my RS site : http://www.evosapien.com/robosapien-hack/knitsu/