|
This is my latestest updated version of Robosapien Autonomous V.1.1 July 09 2005
Now Robosapien is more aware of his surroundings...
He starts by taking a simple reading... in which if something is to Far he continues to move forward, stopping every 3 seconds to take a new reading...
If Robosapien notices something that is getting close, but not to to close, he will call a program, in which will raise his left arm take a reading, lower his arm, and then raise his other arm, causing his head and sensor to pan to the sides getting readings for each sides... Then the chip does a mathamatical equation simply is one side is greater then the other call turn(side) and if the other side is bigger call this side.....
after his turn has happened, he loops back to the beginning of the code resesting his body postion (for best movement/walking straight) and tkaing a reading.....
If something is to to close, and Robosapien recognizes it, he will talk a few steps back, and then call the Cehck sides in which he will take readings from the sides and the side furthest away he will turn to and moveforward...
such problems I encountered were timing the arms to raise fast enough and delay so that the sensor could take a stable reading.. I also fixed this by making the sensor take 3 readings form each side and diving it into 3 giving me a more accurrate value of the sides..
certain updates would include converting the value to CM, or lighting up the BX chips GREEN/RED lights when he is in a certain mode so it is easy to understand when you do not have him plugged into a pc
another update would be something about walking forward a certain amount of times and then take a reading just because he has being walking straight for so long, he might be trapped under a chair/ or something, this might help “glitches” in the system since their is only 1 sensor plugged into him
here is what the BX-24 downloader windows looks like when I turn on my RS and the code below this and let him wander my room for a few minutes.. with my 25 foot cable
*** Finished Downloading
RS Walking Forward RS Walking Forward RS Walking Forward
RS Checking Side Val Val for Right is - 4 Val for Left is - 109 Robosapien TurnRight
RS Checking Side Val Val for Right is - 169 Val for Left is - 4 Robosapien Turn Left
RS Walking Forward RS Walking Forward RS Walking Forward RS Walking Forward RS Walking Forward RS Walking Forward RS Walking Forward RS Walking Forward RS Walking Forward RS Walking Forward RS Walking Forward RS Walking Forward RS Walking Forward RS Walking Forward RS Walking Forward RS Walking Forward
RS Checking Side Val Val for Right is - 145 Val for Left is - 266 Robosapien TurnRight
RS Walking Forward RS Walking Forward
RS Checking Side Val Val for Right is - 85 Val for Left is - 165 Robosapien TurnRight
RS Walking Forward RS Walking Forward RS Walking Forward RS Walking Forward RS Walking Forward RS Walking Forward RS Walking Forward
RS Checking Side Val Val for Right is - 97 Val for Left is - 97 RS Checking Side Val Val for Right is - 100 Val for Left is - 116 Robosapien TurnRight
RS Walking Forward RS Walking Forward RS Walking Forward RS Walking Forward RS Walking Forward
'*********************************************************************************
' Autonomous Robosapien Version 1.0.0.02 Extreme Elimination BETA
'*********************************************************************************
' Robosapien w/ RAMB (BasicX 24) by Chance Brown "knitsu" ' Sharp Infrared Sensor connected to Pin 12 on the BX-24 ' IR PIN from Robosapien connected to Pin 13 on the BX-24
' more Robosapien BX-24 can be found at
' http://evosapien.com/robosapien-hack/knitsu/
' This Program basically allows your Robosapien to wander on his
' own "Autonomously" until the Batteries die, or he get's stuck in a
' tight spot that he cant get proper readings from.
' for adding something new to the program I recommend this:
' trying to add the actual Sensor's robosapien has built in him
' but you will have to find out the IR codes for Program LEFT/RIGHT sensors
' and apply those to the BITS below, where the other RS Control Commands
' are located. This way if Robosapien does get stuck in a corner, or table/chair
' he will most likely hit his sensor and perform the operation you programmed in
' here for that sensor to do, like Walk Back, Walk Back, Left Turn, Left Turn, ROAR
' or something along those lines.
' thanks to all the people that have being helping me out, R.Oschler, Brian.P, T.Andley
' and also to the big man himself M.W. Tilden for creating this amazing Robot for me to
' learn the basics 101 of Robotics, I thank you so much!
'**********************************************************************************
'**********************************************************************************
Option Explicit
Public Const LowBit as single = 0.000833 'Time it takes for the low bit
Public Const StartBit as single = 0.006664 'Time it takes for the start bit
Public Const HighBit as single = 0.003332 'Time it takes for the high bit
Public Const ClockBit as single = 0.000833 'Clock bit time
Dim ValueCentre as Integer ' Name of Centre Sensor Value
Dim ValueLeft as Integer ' Name of Left Sensor Value
Dim ValueRight as Integer ' Name of Right Sensor Value
Dim ValueRightAvg as Integer '
Dim ValueLeftAvg as Integer '
Public Const Sapien As Byte = 12 'Robosapien iR is connected to pin
'12 on the BX-24 'That is labled pin 8 on the motherboard
Const CenterIRPin As Byte = 13 'The sharp Sensor is connected to pin
'13 on the BX-24 'That is labled pin 9 on the motherboard
'*********************************************************************
Public Sub Main()
Do
Call Reading
Loop
End Sub
'*********************************************************************
Sub Reading()
Do
ValueCentre = GetADC(13)
If ValueCentre > 450 Then
Call RSBackup
Call Delay (0.5)
End If
if ValueCentre < 150 THEN ' nothing in sight for a distance
Call RSfoward
End If
Call BackStep
Call Delay(3.0)
Call SensorCentre
Loop
End Sub
'*********************************************************************
' ROBOSAPIEN SHARP SENSOR CENTRE(INFRONT) READINGS
'*********************************************************************
Sub SensorCentre()
Do
Call Putpin(Sapien,1) 'turns the Pin for Robosapien iR ON
Debug.Print"RS Checking Side Values"
Call Delay (3.0)
CALL RIGHTHANDUP
Call Delay (2.0)
ValueRight= GetADC(13)+GetADC(13)+GetADC(13) ' Right Side Value
ValueRightAvg= ValueRight \ 3
Call Delay (0.7)
debug.print"Val for Right is - " ;Cstr(ValueRightAvg)
Call Delay (0.5)
CALL RIGHTHANDDOWN
Call Delay(2.0)
Call LEFTHANDUP
Call Delay (2.0)
ValueLeft=GetADC(13)+GetADC(13)+GetADC(13) ' Left Side Value
ValueLeftAvg= ValueLeft \ 3
Call Delay (0.7)
debug.print"Val for Left is - " ;Cstr(ValueLeftAvg)
Call Delay (0.5)
Call LEFTHANDDOWN
Call Delay (1.0)
If ValueLeft > ValueRight THEN
Call RSRIGHT
Call Delay (0.2)
End If
IF ValueLeftAvg < ValueRightAVG Then
Call RSLEFT
Call Delay(0.2)
End If
Loop
End Sub
'*********************************************************************
Sub RSLEFT()
DO
Debug.Print "Robosapien Turn Left"
Call TurnLeft
Call Delay(3.0)
Call oops
Call Delay (0.5)
Call Reading
LOOP
END SUB
'*********************************************************************
SUB RSRIGHT()
DO
Debug.Print "Robosapien TurnRight"
Call TurnRight
Call Delay (3.0)
Call oops
Call Delay (1.0)
Call Reading
LOOP
END SUB
'*********************************************************************
Sub RSfoward()
Do
Debug.Print"RS Walking Forward"
Call Delay (0.3)
Call ForwardStep
Call Delay (4.0)
ValueCentre= getADC(13)
if valuecentre >150 Then
Call SensorCentre
End If
Loop
End Sub
'*********************************************************************
Sub LEFTHANDUP()
Debug.print"RS Raise LHand"
CALL LARMUP
Call Delay (0.5)
Call LArmUp
Call Delay (0.5)
Call LArmUp
Call Delay (0.5)
End Sub
'*********************************************************************
Sub LEFTHANDDOWN()
Debug.print"RS Lower LHand"
CALL LARMDown
Call Delay (0.5)
Call LArmDown
Call Delay (0.5)
Call LArmDown
Call Delay (0.5)
End Sub
'*********************************************************************
Sub RIGHTHANDUP()
Debug.print"RS Raise RHand"
CALL RARMUP
Call Delay (0.5)
Call RArmUp
Call Delay (0.5)
Call RArmUp
Call Delay (0.5)
End Sub
'*********************************************************************
Sub RIGHTHANDDOWN()
Debug.print"RS Lower RHand"
CALL RARMDown
Call Delay (0.5)
Call RArmDown
Call Delay (0.5)
Call RArmDown
Call Delay (0.5)
End Sub
'*********************************************************************
Sub RSbackup()
Do
Debug.Print"RS Walking Backward"
Call Delay (0.3)
Call BackStep
Call Delay (4.0)
Call StopIt
Call Delay (0.5)
Call SensorCentre
Loop
End Sub
'*********************
Sub Stopit()'Stop It
'10001110
Call Pulseout(Sapien,startbit,0)
Call Pulseout(Sapien,HighBit,1) '7 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '6 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '5 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '4 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,HighBit,1) '3 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,HighBit,1) '2 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,HighBit,1) '1 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '0 bit
Call Pulseout(Sapien,Clockbit,0)
End Sub
'*********************'*********************
Sub TurnRight()'Turn Right
'10000000
Call Pulseout(Sapien,startbit,0)
Call Pulseout(Sapien,HighBit,1)
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1)
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1)
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1)
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1)
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1)
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1)
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1)
Call Pulseout(Sapien,Clockbit,0)
End Sub
'*********************
Sub RArmUp()'Right Arm Up
'10000001
Call Pulseout(Sapien,startbit,0)
Call Pulseout(Sapien,HighBit,1)
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1)
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1)
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1)
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1)
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1)
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1)
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,HighBit,1)
Call Pulseout(Sapien,Clockbit,0)
End Sub
'*********************
Sub RArmOut()'Right Arm Out
'10000010
Call Pulseout(Sapien,startbit,0)
Call Pulseout(Sapien,HighBit,1) '7 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '6 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '5 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '4 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '3 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '2 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,HighBit,1) '1 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '0 bit
Call Pulseout(Sapien,Clockbit,0)
End Sub
'*********************
Sub TltBodyR()'Tilt Body Right
'10000011
Call Pulseout(Sapien,startbit,0)
Call Pulseout(Sapien,HighBit,1) '7 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '6 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '5 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '4 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '3 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '2 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,HighBit,1) '1 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,HighBit,1) '0 bit
Call Pulseout(Sapien,Clockbit,0)
End Sub
'*********************
Sub RArmDown()'Right Arm Down
'10000100
Call Pulseout(Sapien,startbit,0)
Call Pulseout(Sapien,HighBit,1) '7 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '6 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '5 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '4 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '3 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,HighBit,1) '2 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '1 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '0 bit
Call Pulseout(Sapien,Clockbit,0)
End Sub
'*********************
Sub RArmIn()'Right Arm In
'10000101
Call Pulseout(Sapien,startbit,0)
Call Pulseout(Sapien,HighBit,1) '7 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '6 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '5 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '4 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '3 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,HighBit,1) '2 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '1 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,HighBit,1) '0 bit
Call Pulseout(Sapien,Clockbit,0)
End Sub
'*********************
Sub WalkForward()'Walk Forward
'10000110
Call Pulseout(Sapien,startbit,0)
Call Pulseout(Sapien,HighBit,1) '7 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '6 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '5 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '4 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '3 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,HighBit,1) '2 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,HighBit,1) '1 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '0 bit
Call Pulseout(Sapien,Clockbit,0)
End Sub
'*********************
Sub WalkBack()'Walk Backwards
'10000110
Call Pulseout(Sapien,startbit,0)
Call Pulseout(Sapien,HighBit,1) '7 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '6 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '5 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '4 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '3 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,HighBit,1) '2 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,HighBit,1) '1 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,HighBit,1) '0 bit
Call Pulseout(Sapien,Clockbit,0)
End Sub
'*********************
Sub TurnLeft()'Turn Left
'10001000
Call Pulseout(Sapien,startbit,0)
Call Pulseout(Sapien,HighBit,1) '7 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '6 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '5 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '4 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,HighBit,1) '3 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '2 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '1 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '0 bit
Call Pulseout(Sapien,Clockbit,0)
End Sub
'*********************
Sub LArmUp()'Left Arm Up
'10001001
Call Pulseout(Sapien,startbit,0)
Call Pulseout(Sapien,HighBit,1) '7 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '6 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '5 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '4 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,HighBit,1) '3 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '2 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,LowBit,1) '1 bit
Call Pulseout(Sapien,Clockbit,0)
Call Pulseout(Sapien,HighBit,1) '0 bit
Call Pulseout(Sapien,Clockbit,0)
End Sub
|