• Aucun résultat trouvé

I

~

: . ... .•..l

A

"-L _~···· ..__ J

Joystick Operation

Source Code

wish to move.Thanks to these two tasks, if you want to movethe servomotoron pin26state in the code "L I=2000 ."

SinceTripod1 taskis always runningin thebackground, the next time it comes aro und its loop it will dete ct and send thenew valueofII outas apulseou t comma nd. The servo-mot or that is con nec ted to I/O pin 26 will move to the posit ion that the valueof 2000 represen ts.

Fluffy'ssourcecode is exte ns ive. It hasbeen included in this feature as anadde nd um.Othe r useful inform ati on, includ-ing sche ma t ic drawinclud-ings, areava ilableatBasicX .com.

Thenext thi ngtodoisdet ermineifajoystickisplugged in. Ifajoystick is prese nt, itspot 2is con nec te d topin 4of the BasicX.If,whenreadingpin 4of theBasicX areading of 0 is obta ine dat themicrop rocessor,theprogramdeterminesthat there is no joystick present and "Task3" is executed. The robot begin s running in auto no mo us mod e (we willcome back to this later).This is accomplishe d with the Rctime comm and .Ifany valueothe r than 0 isreturned, the micro-processor activates thejoysti ck contro l mod e.

This contro l mod e read s the jo ysti ck 's two pots, then bran ch es to a subro ut ine that plays a "script"of servo mo tor positionsthat mat ch thejoystick positi on, i.e.,ifyou mov e thejoystick forwardFluffywill walkforward , andso on. The twojoystick butto nsalsoactas amean s ofcontrol. If pushed , button one (I/O pin 1) will call the centersubrout ine and cause all the servo motorsto move to the irhom e posit ions.

Thisisveryhelpfulforinitial servo motor hookup and align-men t. Ifyou pressbutton two (pin 2), the BasicX program willcall thelow subro ut ineand causetheHexapodto crouch.

Thishasnoreal use,but it'sreall y coolto watch! As men-tion ed earl ier, ifa joyst ick isnot det ect ed when therobot firstboot sup,the programcalls Task3 andstarts its auto no -mous mod e. Once sta rted, Task3 will make sure that the sona rservo mo tor initi al positi on is straigh t-a hea d. It then gets distan cedat a from the sona r unit (If0 pin 28 and32) to det ermineif there is anyobjec t in front of it closer than 23 inch es.Ifno objec tsare det ect ed closer than 23 inch es, it calls the forwardsubro ut ine and sta rts thedet ecti on loop overagain.Ifthe sona r unit det ects any objec t closer than 23inch esit willcalltheSon looksubrout ine.The Son loo k subro ut ine will then take con trolof the variable 'Son' and directthe sona rservo motor toturnthesona r unittotheleft and then to theright if there is st illan object in itspath .If afte r three atte mpts the Son look subro ut ine cannot find a clear pathfor the robot to travel, it willcall the backw ard subro ut ine. Afte r backing up, the robot will start looking for aclearpath again .

ROBOTSCIENCE&TECHNOLOGY

'BasicX controllerboard Call Forward go to - forward'

'Fluffy code v l with sonar Elseif pot 1>400 Then 'Ifjoystick isnotforward

'CompiledSize1364 Bytes Call Backward but it is backward gore

'ByCh ris Harr iman, 1998 backward'

Elseif pot2 = 1 Then 'Ifthe joystic k leftgo to -DimStack 1(l to40 ) as Byte 'Set 40bytes torun taskI' Call Left left'

DimStack3(l to40 ) as Byte 'Set 40 bytes to run task 3' Elseif pot2 >400 Then 'Ifthejoystic k isnot left but Stack2( 1to40) as Byte 'Set 40 bytes to run task 2' Call Right it is rightgotoright'

Dim Ll AsInteger 'Set variable Ll asinteger End if 'End allif statements'

Dim L2 AsInteger 'andso-on' Loop 'Goto do at thetop'

Dim Ll iAsInteger 'and so-on' End Sub 'Marks theendof this sub'

Dim L2iAsInteger 'and so-on'

DimS1AsInt eger Sub TripodI ()

Dim S2AsInteger

Dim S I iAsInteger Do

Dim S2iAsInteger Call Pulseout(26,Ll ,l) 'Send valueof Ll asa pulse

Dim Potl AsInteger 'joyst ick variable X Axis' out pin 26'

Dim Pot2 AsInt eger 'joystickvariable Y Axis' Call Pulseout( 22,Ll ,I) 'Send valueofLl asa pulse

DimSonAsInt eger 'Sonarservo position variable out pin 22'

Dim DisAsInteger 'Sonardist.measurevariable' Call Pulseout(36,Ll i,I) 'Sendvalueof Ll asa pulse out pin 36'

Sub Main() Call Pulseout(35 ,S

n,

I) 'Send valueof Ll asa pulse

out pin35'

Call Centerposition 'Set allservostohomeposition' Call Pulseout( 25,Sl ,1) 'Send valueof Ll as a pulse

Call Sleep(64) 'Wait for64/5 12seconds' outpin25'

Calltask "Tripod I",Stackl 'Starttripod sideone taskup' Call Pulseout(21,SI ,I ) 'Sendvalueof Ll as a pulse Calltask "Tripod2",Stack2 'Start tripodside two task up' out pin 21'

Call Putpin(4,0) Loop

Call Sleep(4) End Sub

Pot2 =Rctimet-l.O)

If Pot2 =0Then 'If joystickisnot present

Callt ask "task3",Stack3 start auto no mous mode' Sub Tripod2() Do

Loop Do

Else 'O therwisereadjoystick Call Pulseout(3 8,L2i,l ) 'Sendvalueof Ll as a pulse

~)lItpin 38'

End if inputs' Call Pulseout(34,L2i,l ) 'Send value of Ll as a pulse

Do out pin 34'

Call Putpin(3,O) 'Discharge capon pin3 toget Call Pulseout( 24,L2,1) 'Send value of Ll asa pulse

ready to readpot1' out pin 24'

Call Putpin (4,0 ) 'Discharge capon pin4 to Call Pulseout(23,S2,1) 'Send valueofLl asa pulse

get ready toreadpot2 ' out pin23'

CallSleep(4) 'Wait for caps todisch arge' Call Pulseouti.I7,S2i,1) 'Send valueofLl asa pulse

Pot! =Rct imel-l.O) 'Read valueof joystickpod out pin37'

on pin4' Call Pulseout(33 ,S2i,1) 'Send valueofS2asa pulse

Pot 2= Rct ime(3,O) 'Read valueofjoyst ick pot! out pin33'

on pin3' Call Pulseoutt27.Son,I) 'Send valueof Sonas a pulse

IfGetpin(2)=

°

Th en 'Read joystic kbutton I' out pin27'

Call low 'Ifjoystick button 2pressed Loop

go to sub low' End Sub

Elseif Get pin (1)=

°

Then 'If joystick butto n 1 pressed

Call Cente r go to - Cente r'

Elseifpot1= 1Then 'If joystickpushed forward

II.'

ROBOTSCIENCE&TECHNOLOGY

I

i

j

'Auto no mous mode TASK' 'Waitfor 256/512thseconds'

'Startof the Doloop '

'Move Sona rservo to cente r' 'SetINTonsonar board high' 'Wa it forECHOto golow&

store in Dis' 'DisableSonar'

'Tum Disvalue into inc hes' 'IfDis more than 23"then ' 'Goto subSonlook' 'Othe rwise'

'Call the ForwardSub' 'End ifsta tement usage' 'Gotothetop'

-7'"--- -- - -- - - - -- -- - - - - - - - - - - - - - - -

-'Afterturni ng rightexit sui' 'IfDislessthan 23" dothis'

'End ifstatement usage'

'If timeoutcounte rX=3rh 'Call Backward 2times' 'SetINTonsona r boardhig 'Wait forECHO to golow

store in DIS' 'DisableSonar'

'Turn Disvalue intoinches 'If Dismorethan 23"then' 'Callturn right 2times'

'After Backing up exit sub' 'IfX= lessthan 3 then' 'End ifsta temen t usage' 'Go toDo on top'

'Afterturningleftexit sub' 'IfDislessthan 23" dothis' 'End if state ment usage' 'Movesonarservo to the rig 'Set INTonsona r boardhi 'WaitforECHOtogolow

store in Dis' 'Disable Sona r'

'TumDisvalue into inches

'If Dismorethan 23"then'

'Call turn left2times' 'TopoftheDO loop' 'Loopcoun teradd 1 to valu 'Movesonarservotothe I

Call Putpin (28,0 )

'Lookaround fornewpath sub'

'Set Xasa byte variable' 'MakeX = 0'

'Squatallleg servos godown' 'Move allservostohomepas' 'Shoulder2 back'

ROBOTSCIENCE&TECHNOLOGY

Howto

Documents relatifs