You might be absolutely correct.
I suppose an echo has a significant energy distribution pattern which is a function of the angle on incidence. I do not know the physics but it certainly seems reasonable.
Thank you!
Ken
Science, Technology, Engineering - not so much math
Got a new video to show you all. The code is much the same as the last time. I included it below.
The video speaks for itself. Would this be a good context for a public school engineering project? It certainly shows the real world as I know it. The kids could see whether they can make the car go around the room staying outside traffic cones which define the inside of the course.
http://www.youtube.com/watch?v=V2ZjYw9MOz0
Code:
'************************************************* ***************
SYMBOL trigright = PORTB.0 ' Define output pin for Trigger pulse
SYMBOL trigfront = PORTB.1 ' Define output pin for Trigger pulse
SYMBOL trigleft = PORTB.3 ' Define output pin for TRigger pulse
SYMBOL echoright = PORTC.6 ' Define input pin for Echo pulse
SYMBOL echofront = PORTC.5 ' Define input pin for Echo pulse
SYMBOL echoleft = PORTC.7 ' Define input pin for Echo pulse
SYMBOL radiotransmitterON = PORTC.4 ' Define input pin for Signal
'inside radio receiver indicatin that the transmitter has
'been turn on. Used to stop the car by turning ON the xmitter.
TRISC = %11110000
DATA $1C,$B5'This version's checksum goes here.
' Speed of sound echo is about 2mS per foot distance.
' define pulsin_max 2800 '28mS SF05 spec says it drops at 30mS.
' don't forget channel 3 every 20mS or 50Hz.
'--------------------
frontdanger CON 180 'about 12 inches. Was 450 about 30 inches
stopreversing CON 390' about 26 inches
frontfree CON 1080 'about 72 inches. Was 800 about 53 inches.
desiredtrack CON 540 'about 36 inches. Now only one line.
'outertrack con 450 'about 30 inches. Was 360 about 24 inches
SYMBOL turnon = PORTC.3 ' the signal that if HIGH makes the car steer straight
SYMBOL steerto = PORTC.2 ' the signal that if on turning is on, then decides
'the direction
SYMBOL stopgo =PORTC.1 ' the signal that if HIGH makes the car go
SYMBOL forrev =PORTC.0 ' the signal that if on and is not on stop makes
'the car reverse
'---------------------------
rangeleft VAR WORD 'experimental timing.
rangeright VAR WORD
rangefront VAR WORD
oldrangeright VAR WORD
oldrangefront VAR WORD
CNTR VAR WORD
CNTR = 0
CNTL VAR WORD
CNTL = 0
steeringstate VAR WORD
steeringstate = 0 ' 0=straight,1=left,2=right,3=skid left,4=rightback,
'--------------
'Looks like I need to kick the steering back into straight.
LOW stopgo 'stop
HIGH turnon
'pause 2000 'Wait so I can put the car down and get out of the way.
main:
GOSUB triggers
CheckIfInDanger:
IF (rangefront < frontdanger) AND (steeringstate <> 3) THEN
HIGH stopgo 'go
LOW forrev 'back
LOW turnon 'steer
LOW steerto 'right
steeringstate = 4
GOTO reverseoutoftrouble
' loop till this is secured
ENDIF
tryleftturn:
IF rangefront < frontfree THEN
'something ahead - turn hard left.
'gosub leftforward
IF (steeringstate <> 3) THEN
HIGH stopgo 'go
LOW forrev 'reverse
LOW turnon 'steer
HIGH steerto 'left
steeringstate = 3 'skid left
PAUSE 150
ENDIF
HIGH steerto 'left
HIGH stopgo 'go
HIGH forrev 'forward
GOTO main 'Loop until secured
ENDIF
goingforward:
keepgoingforward:
IF (rangeright < desiredtrack) THEN
'steer left
CNTL = (CNTL+1)
IF CNTL = 2 THEN
LOW turnon 'steer
HIGH steerto 'left
steeringstate = 1
HIGH stopgo 'go
HIGH forrev 'forward
CNTL = 0
ENDIF
PAUSE 150
ENDIF
IF (rangeright > desiredtrack)THEN
'steer right
CNTR = (CNTR+1)
IF CNTR = 2 THEN
LOW turnon 'steer
LOW steerto 'right
steeringstate = 2
HIGH stopgo 'go
HIGH forrev 'forward
CNTR = 0
ENDIF
PAUSE 150
ENDIF
IF steeringstate = 1 THEN 'left
LOW steerto 'right
PAUSE 100
ENDIF
IF steeringstate = 2 THEN 'right
HIGH steerto 'left
PAUSE 60
ENDIF
HIGH turnon
steeringstate = 0
GOTO main
'-------------------------
reverseoutoftrouble:
' below seems reduncant except for the pause.
LOW turnon 'steer
LOW steerto 'right
steeringstate = 4 'new steeringstate
HIGH stopgo 'go
LOW forrev 'back
PAUSE 200 'added to do some reversing. We have a problem of bumping
'against the wall and not backing up. This pause should fix that.
keepreversing:
WHILE (rangefront < stopreversing) OR ((oldrangefront = rangefront) AND (oldrangeright = rangeright))
' We have not reversed far enough
HIGH stopgo 'go
LOW forrev 'back
PAUSE 250 'maybe this will get car to back off wall
GOSUB triggers
WEND
'------------------------------------
'done reversing. Go straight or turn left depending on right
'ping. If > outertrack then out in the middle. If < desiredtrack
'then stuck on wall. This did not work. See TOY_CAR_KICK_TURN_3.wmv
'Try no IF statement.
'if rangeright > desiredtrack then
'steer left
LOW turnon 'steer
HIGH steerto 'left
steeringstate = 1
HIGH stopgo 'go
HIGH forrev 'forward
PAUSE 250
'hpwm 2,Forward,50 --Already going Forward
'endif
GOTO main
'--------------------------
triggers: ' Check two sonars and xmitter ON signal.
oldrangeright = rangeright
' produce 10uS trigger pulse (must be minimum of 10uS)
LOW trigright
HIGH trigright
HIGH trigright
HIGH trigright
LOW trigright
'zero could be legal below
PULSIN echoright,1,rangeright 'measures the range in 10uS steps
PAUSE 10 'Wait for ringing to stop - read SF05 spec.
'pulsin echoleft,1,rangeleft 'see if this slows the triggers to one
'per second. That it did, but it crashed straight into the wall.
pulsf:
oldrangefront = rangefront
LOW trigfront
HIGH trigfront
HIGH trigfront
HIGH trigfront
LOW trigfront
PULSIN echofront,1,rangefront ' measures the range in 10uS steps
PAUSE 10
radioON:
' make ON = LOW for 1/10 toy car to radiotransmitter
do WHILE radiotransmitterON = 0
LOW stopgo
loop
HIGH stopgo 'get going again
RETURN
END
I certainly do agree about kids learning....
However, the only way to reach the students in a public school is through the teachers and the administrators. My question is what is the best way to communicate to them. It is a marketing issue. A teach-the-teacher issue.
Ken
Thanks, you got me started
I have not been planning on adding sensors. I might change the SONAR for IR. I know nothing about the details.
For speed I was planning on dividing distance traveled by time between measurements. For angles, I agree, the SONAR's have a vague and varying pattern. Hence the 'speed' calculations may be inconsistent.
With the hobby level car I have complete proportional control of both steering and wheel power. If I could get a PWM system that is truly 50htz (my present system is not. It was calibrated by trial and error) then I would have a great deal of flexibility - the better to speed up the car. Then a parameter passing GOSUB would be very convenient.
Ken
What I am trying to write is...
I would like to use the 4 Meg counter to measure time in seconds and the SONAR responses to measure distance in inches.
I could then set up CONstants that would be recognizable
and measurable by middle school students with a yardstick and a watch with a second hand.
How?
Ken
How do I make hex memory look digital?
My robocars have no LEDs. They have no debugger and no break points. Using PICkit 2 I can read EEPROM. My code can write in that area using the WRITE command.
When I have my car on blocks connected via the PICkit2 USB cable, I would like to do a READ and see in the EEPROM section some words that the code placed there while it ran represented as decimal numbers.
hex includes the digits 0-9. Is there a library routine or a command to which I can give a WORD containing a positive hexadecimal number (for example the response from a SONAR) and it will return that number in decimal format represented with the digits 0-9 in least significant (as read by PICkit2) to the right?
Ken