ROBODYSSEY SYSTEMS LLC
Product Catalog
Code Page
Policies
Gallery
Whats New
Press Releases
Resources
Links
Contact Us
About Us
Press
Educators Page
BasicX and Robotics book
After School
Mini Challenge!
Hack-A-Toy
Shopping Cart
Home Product Catalog Shopping Cart Resources Links
Code Page Policies Gallery

Shivang Patel's soccerbot code in microBasic

program Shivangsoccer

dim ch0,ch1,ch2,ch3,ch4 as word 		'Variables storing data fromthe IR sensors
dim dri,value as word          			'Direction and IR value variables
dim Read1,Read2,Read3 as word  		'Variables for a single buttercup
dim see,saw as word            			'Variables for the sharp sensors
'*********************
sub procedure Forward
portb=%00011101
end sub
'*********************
sub procedure Reverse
portb=%00101011
end sub
'*********************
sub procedure T_left
portb=%00011011
end sub
'*********************
sub procedure T_right
portb=%00101101
end sub
'*********************
sub procedure halt
delay_ms(50)
portb=0
end sub
'**********************
sub procedure walls
		'This did not work on Shivangs robot.!!!
		'Detecting the walls needs to be fixed!!!
saw=adc_read(3) 	 'Right IR Sensor
see=adc_read(4) 	 'Left IR Sensor
if saw > 400 then
Reverse
delay_ms(500)
T_left
delay_ms(500)
end if
if see > 400 then
Reverse
delay_ms(500)
T_right
delay_ms(500)
end if
end sub
'*****************************************************
sub procedure ScanTest
' ScanTest changes which IR sensor is being viewed. The thing to watch
' is what direction your sesors face. Alex and Shivang have the Ch0 in the front
' Kevin his in the rear.  Bottom line, whatch your sensor locations!

' Alex and Kevin have their code in the clearbit, setbit mode. Since
' nothing else is connected to PortC you can switch to this mode if you like.
' If your fine with it, just leave it

portC = %00000000 'Channel 0
ch0=adc_read(0)   ' Input the value into PortA Pin0

portC = %00000001 'Channel 1
ch1=adc_read(0)   ' Input the value into PortA Pin0

portC = %00000010 'Channel 2
ch2=adc_read(0)   ' Input the value into PortA Pin0

portC = %00000011 'Channel 3
ch3=adc_read(0)   ' Input the value into PortA Pin0

portC = %00000100 'Channel 4
ch4=adc_read(0)   ' Input the value into PortA Pin0

end sub
'*****************************************************
sub procedure ToBlack
'This sub procedure checks to see if the robot is heading in the correct direction
'Shivang and I reasoned that all we need to do is get close. Let's face it. the
'goal is 3/5 of the end. That means if we are heading in the right direction,
'we could score a goal 3/5 of the time we control the ball....Not bad

'This routine only uses one buttercup. In general, it simply wants to make sure
'the value the buttercup is seeing is getting darker. Remember, the darker it is,
'the bigger the number.

Read1 = adc_read(2)     'Collect data from one buttercup
Forward                 'Call a forward
Delay_ms(125)           '!!!!!!!CHANGE THIS VALUE TO FIT YOUR ROBOT!!!!!!!
                        'That says go forward for 0.5 seconds. If your robot is
                        'quick, that is way too far!
                        'Since Shivangs robot was as slow as a turtle on sleeping
                        'pills we needed it to go 0.5 seconds to see it move!
Read2 = adc_read(2)     'Get a second reading from the butter cup
If Read1 > Read2 Then   'IF the first reading was darker than the second then....
      T_Right
      Read3 = Read1 - Read2   'let's see how mach darker.
      If Read3 > 50 Then 'OK if the difference between read1 and read2 was at least
                         '25 then we must be going the wrong way!....So...
                         'Turn right for....
      Delay_ms(500)      'Again remember the sleeping turtle! you will likely
                         'need less than 1.5 seconds!
      End If
      delay_ms(200)
End If
end sub
'********************************************
sub procedure ToWhite
'This sub procedure checks to see if the robot is heading in the correct direction
'Shivang and I reasoned that all we need to do is get close. Let's face it. the
'goal is 3/5 of the end. That means if we are heading in the right direction,
'we could score a goal 3/5 of the time we control the ball....Not bad

'This routine only uses one buttercup. In general, it simply wants to make sure
'the value the buttercup is seeing is getting darker. Remember, the darker it is,
'the bigger the number.

Read1 = adc_read(2)     'Collect data from one buttercup
Forward                 'Call a forward
Delay_ms(125)           '!!!!!!!CHANGE THIS VALUE TO FIT YOUR ROBOT!!!!!!!
                        'That says go forward for 0.5 seconds. If your robot is
                        'quick, that is way too far!
                        'Since Shivangs robot was as slow as a turtle on sleeping
                        'pills we needed it to go 0.5 seconds to see it move!
Read2 = adc_read(2)     'Get a second reading from the butter cup
If Read1 < Read2 Then   'IF the first reading was darker than the second then....
      T_Right
      Read3 = Read1 - Read2   'let's see how mach darker.
      If Read3 < 50 Then 'OK if the difference between read1 and read2 was at least
                         '25 then we must be going the wrong way!....So...
                         'Turn right for....
      Delay_ms(500)      'Again remember the sleeping turtle! you will likely
                         'need less than 1.5 seconds!
      End If
      delay_ms(200)
End If
end sub
'************************************
sub procedure theif
'this code first sets out to see which IRsensor has the lowest value
'Remeber, the lower the value, the more IR it sees

'The Data for this was collected up in the "ScanTest" Sub Procedure above
if ch0 < ch1 then  'If the data from the sensor on Ch0 is less than whats on CH1 then..
value = ch0        'value is equal to the data from sensor on ch0
dri = 0            'the variable used to choose direction is 0
end if

if ch1 < ch0 then  'If the data from the sensor on Ch1 is less than whats on CH0 then..
value = ch1        'value is equal to the data from sensor on ch1
dri = 1            'the variable used to choose direction is 1
end if

if ch2 < value then'If the data from the sensor on Ch2 is less than whats in value then..
value = ch2        'value is equal to the data from sensor on ch2
dri = 2            'the variable used to choose direction is 2
end if

if ch3 < value then'If the data from the sensor on Ch3 is less than whats in value then..
value = ch3        'value is equal to the data from sensor on ch3
dri = 3            'the variable used to choose direction is 3
end if

if ch4 < value then'If the data from the sensor on Ch4 is less than whats in value then..
value = ch4        'value is equal to the data from sensor on ch4
dri = 4            'the variable used to choose direction is 4
end if
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'!!!!!!!!!! Major Important stuff below !!!!!!!!!!!!!!!!!!!!!
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if value > 500 then 'See that 500???? that is a threashold! You need to set this for the
                    'IR light at the MAll!!!! If the amount of IR at the Mall is
                    'around 800 or 900, then this number needs to be changed.
                    'Think about it!! If the light at the mall is around 450
                    'then your robot will take off chasing the stupid lights.
                    'I personally would be very embarassed if my robot made friends
                    'with a Macy's sign
halt
end if
'Okay, here is the guts of the program. This is going to need to be adjusted for your own bot.
'Kevin, your bot has the ch0 in the rear. Alex and Shivang, yout ch0 is in the front.
'don't just copy this and think it is going to work....you have to think about where your
'sensors are and how you want it to behave
select case(dri)     'go back up and see where the variable dri is filled.
case 0               'If dri is 0 then....
 if value < 500 then 'Check that threashold. I don't want to chase a Macy's sign!
 Forward             'Okay, it's not a sign...let's go get it!
    if value < 50 then 'Woa! we are close to the ball!! we should see if we are
     ToBlack
     'ToWhite           'going the right direction!!!
    end if
 end if
case 1               'If dri is 1 then....
 if value < 500 then
T_left
 end if
case 2               'If dri is 2 then....
  if value < 500 then
T_left
 end if
case 3               'If dri is 3 then....
  if value < 500 then
 T_right
 end if
case 4               'If dri is 4 then....
 if value < 500 then
 T_right
 end if

end select
end sub
'****************************************************
main:
  trisb = 0
  trisc = 0
  trisa = %00011111
  adcon1 = %10000000
while true
 dri=0              'Let's start out saying that the sensor hooked to ch0 is lowest
                    'Kevin! you may want to change this to a 3!!!!
 value=0            'This is OK..it will change on the first scan
ScanTest            'Check all the IR sensors
theif               'Make a decision on the data
wend
end.

Home Product Catalog Shopping Cart Resources Links
Code Page Policies Gallery

Robodyssey Systems manufactures Robot Kits including Autonomous Mobile Walking Robots, Wheeled Robots, Talking Robots, Expressive Robots, and Social Robots. We also sell Robotics Accessories including Nexcell NiMH AA Rechargeable Batteries, Nexcell NiMH AAA Rechargeable Batteries, Battery Holders, Velcro Straps for Battery Packs, Battery Chargers, Robot Grippers, Hobby Servos, Servos Modified for Continuous Rotation, Tail Wheels for all Rolling Robotic Platforms, Polyurethane Skate Wheels with Servo Adapter Hubs, Sharp IR Sensors and Adjustable Sensor Brackets, Sensor Cables, and Programming Cables. All of our Robot Kits can be purchased as easy to assemble robot kits or as fully assembled stationary or mobile robots. Robodyssey uses 1/8 inch aluminum and acetyl for most all of our mobile robot components and robotics accessories. We provide classroom training for teachers interested in integrating robotics, computer programming and electronics into the classroom.

We hope you enjoy our web site. Feel free to use any robotic resources. Robodyssey is your complete solution for Educational Robotics as well as Hobby Robotics.