+ Reply to Thread
Results 1 to 3 of 3

Thread: New to programming, Object avoidance bot. How's my programming look??? Thanks!

  1. #1

    Default New to programming, Object avoidance bot. How's my programming look??? Thanks!

    Alright, it is for a BOE bot for object avoidance.
    Using:
    BS2
    2 motors (not servos),
    1 servo w/ PING))) sensor
    I won't have an opportunity to actually test the code until tomorrow. I'm sure something will be wrong with it though. I would appreciate it if anyone with expirience could read through it and let me know why I might have any problems. Thanks!!
    Code:
    'Mad Max is about to blow something up - MadMax.bs2
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    
    'Definitions-----------------------------------------------------------------
    
    
    DEBUG "I'm bad company."
    
    
    'I/O Pin Definitions
    LeftMotor                 PIN 0
    RightMotor                PIN 1
    Servo                     PIN 14
    Ping                      PIN 15
    Audio                     PIN 7
    Speakers                  PIN 8
    
    
    'Constant/Variable Declarations
    time VAR Word                      'Variables - name/VAR/size, word (0-65535)
    rawDist VAR Word                   'bit(0-1), Nib(0-15), Byte, (0-255)
    counter VAR Word
    inches VAR Word
    leftvalue VAR Word
    rightvalue VAR Word
    RawToIn CON 889
    RawToCM CON 2257
    Trigger CON 5
    Scale CON $200
    IsHigh CON 1
    IsLow CON 0
    
    
    'Motor Initialization
    PAUSE 2000
    LOW LeftMotor                'Initalize motor I/O pins to output low
    LOW RightMotor
    HIGH LeftMotor
    HIGH RightMotor
    PAUSE 100                    'Let the motor circuits wake up
    FOR counter = 1 TO 10        'Servo center
    PULSOUT Servo, 720
    PAUSE 20
    NEXT
    
    
    'MAIN------------------------------------------------------------------------
    
    
    DO
    
    
    GOSUB Get_Sonar
    
    
    IF (inches < 8) THEN           'When obstacle is less than 8 inches away:
    PULSOUT LeftMotor, 2000       'motors stop
    PULSOUT RightMotor, 2000
    PAUSE 500
    GOSUB Servo_Look
    
    
      IF (leftvalue < rightvalue) THEN
    GOSUB Turn_Right
      ELSEIF (leftvalue > rightvalue) THEN
    GOSUB Turn_Left
      ELSEIF (leftvalue + rightvalue < 5) THEN
    GOSUB Turn_Around
      ELSE
    GOSUB Turn_Around
      ENDIF
    
    
    ELSE
    PULSOUT LeftMotor, 3000                     'Left motor forward full speed
    PULSOUT RightMotor, 3000                    'Right motor forward full speed
    ENDIF
    
    
    LOOP
    
    
    'SUBROUTINES------------------------------------------------------------------
    '-----------SONAR-------------------------------------------------------------
    Get_Sonar:                              'Gets sonar from straight ahead
    Ping = IsLow
    PULSOUT Ping, Trigger
    PULSIN Ping, IsHigh, rawDist
    rawDist = rawDist */ Scale
    rawDist = rawDist / 2
    inches = rawDist ** RawToIn
    RETURN
    
    
    Get_Sonar_Left:                        'Gets sonar from left
    Ping = IsLow
    PULSOUT Ping, Trigger
    PULSIN Ping, IsHigh, rawDist
    rawDist = rawDist */ Scale
    rawDist = rawDist / 2
    leftvalue = rawDist ** RawToIn
    RETURN
    
    
    Get_Sonar_Right:                       'gets sonar from right
    Ping = IsLow
    PULSOUT Ping, Trigger
    PULSIN  Ping, IsHigh, rawDist
    rawDist = rawDist */ Scale
    rawDist = rawDist / 2
    rightvalue = rawDist ** RawToIn
    RETURN
    
    
    '-------------------------SERVO MOVEMENT----------------------------------------
    Servo_Look:
    FOR counter = 1 TO 50                  'Servo left
    PULSOUT Servo, 1250
    PAUSE 500
    NEXT
    GOSUB Get_Sonar_Left                   'get left distance
    FOR counter = 1 TO 50                  'Servo right
    PULSOUT Servo, 300
    PAUSE 500
    NEXT
    GOSUB Get_Sonar_Right                  'get right distance
    FOR counter = 1 TO 50                  'Servo center
    PULSOUT Servo, 720
    PAUSE 500
    NEXT
    RETURN
    
    
    '-------------------------------------------MOTOR TURNS------------------------
    'Assuming 1000 turns motor full speed backward, 2000 makes motor stop, 3000 full
    'speed forward.  Adjust accordingly to align motors.
    
    
    Turn_Left:
    PULSOUT RightMotor, 2500                   'Right motor forward
    PULSOUT LeftMotor, 1500                    'left motor reverse
    PAUSE 2000
    RETURN
    
    
    Turn_Right:
    PULSOUT RightMotor, 1500                   'Right motor reverse
    PULSOUT LeftMotor, 2500                    'left motor forward
    PAUSE 2000
    RETURN
    
    
    Turn_Around:
    PULSOUT RightMotor, 1500                   'right motor reverse
    PULSOUT LeftMotor, 1500                    'left motor reverse
    PAUSE 1000
    PULSOUT RightMotor, 1500                   'right motor reverse
    PULSOUT LeftMotor, 2500                    'left motor forward
    PAUSE 2000
    RETURN
    Again, Thank you! I don't exactly know what I'm doing yet.

  2. #2

    Default Re: New to programming, Object avoidance bot. How's my programming look??? Thanks!

    Depending on the motors they probably will not work directly from the stamp pins and without current limiting resistors you may damage the stamp. Make sure you understand what you are doing before connecting power. It would help if we knew how you had things connected.

  3. #3

    Default Re: New to programming, Object avoidance bot. How's my programming look??? Thanks!

    The motors are wired from programmable pins to transistors. This is the reason I cannot test the code tonight, because I need to put resistors on the board in between the programmable pin and the transistor, which I do not have here.

    How do you go about programming the motors if not from the stamp pins?

+ Reply to Thread

Similar Threads

  1. Replies: 2
    Last Post: 08-11-2009, 03:46 PM
  2. object oriented programming: pointer passing
    By Chris Micro in forum Propeller 1 Multicore Microcontroller
    Replies: 14
    Last Post: 05-15-2009, 03:47 PM
  3. Object Oriented Programming (OOP) with ICCv7
    By Peter Verkaik in forum Propeller 1 Multicore Microcontroller
    Replies: 2
    Last Post: 11-07-2008, 12:15 AM
  4. Programming pulse width modulation on the Propeller Chip. Also, programming an
    By Alerk in forum Propeller 1 Multicore Microcontroller
    Replies: 4
    Last Post: 09-26-2008, 12:41 PM
  5. object avoidance bot
    By lobo in forum BASIC Stamp
    Replies: 4
    Last Post: 01-07-2007, 03:42 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts