Shop OBEX P1 Docs P2 Docs Learn Events
Stumped by SumoBot — Parallax Forums

Stumped by SumoBot

zombotzombot Posts: 1
edited 2011-02-01 19:12 in Robotics
I'm working on building a small conveyor system using a cannibalized SumoBot but will admit that I am absolutely terrible at programming. I thought I was on track but am totally stumped.

The idea is to use one fixed roller and one servo to drive a conveyor belt. I want the conveyor to activate when IR Sensor # 1 is tripped and deactivate when IR Sensor # 2 is tripped.

If anyone can point out where I'm going wrong it would be much appreciated.
' Conveyor Test.BS2
' {$STAMP BS2}
' {$PBASIC 2.5}

' -----[ I/O Definitions ]-------------------------------------------------

RMotor       PIN        12                      ' right servo motor
LfIrOut      PIN        4                       ' left IR LED output
LfIrIn       PIN        11                      ' left IR sensor input
RtIrOut      PIN        15                      ' right IR LED output
RtIrIn       PIN        14                      ' right IR sensor input

' -----[ Constants ]-------------------------------------------------------

LED          CON        0                      ' defines LED constant
RFWD         CON        700                    ' sets RFWD speed for RMotor
RSTOP        CON        750                    ' sets stop point for RMotor

' -----[ Variables ]-------------------------------------------------------

irBits       VAR        Nib                     ' storage for IR target data
irLeft       VAR        irBits.BIT1
irRight      VAR        irBits.BIT0

' -----[ Initialization]--------------------------------------------------

Reset:
  LOW RMotor                                    ' initialize motor outputs
  PAUSE 3000                                    ' time to disconnect cable


' -----[ Program Code ]----------------------------------------------------

Main:

  GOSUB Read_IR_Sensors                         ' jumps to Read IR Sensor subroutine
  IF irLeft = 1 THEN GOSUB Run_Conveyor         ' if IR sensor 1 registers object, go to Run Conveyor subroutine
  PULSOUT RMotor, RSTOP                         ' stop motor
  PAUSE 20
  GOTO Main                                     ' loop program

  END


' -----[ Subroutines ]-----------------------------------------------------

Read_IR_Sensors:

  FREQOUT LfIrOut, 1, 38500                     ' modulate left IR LED
  irLeft = ~LfIrIn                              ' read input (1 = target)
  RETURN

Read_IR_Sensors_2:

  FREQOUT RtIrOut, 1, 38500                     ' modulate right IR LED
  irRight = ~RtIrIn                             ' read input (1 = target)
  RETURN


Run_Conveyor:

  PULSOUT RMotor, RFWD                          ' turns conveyor motor on
  GOSUB Read_IR_Sensors_2                       ' checks IR sensor #2
  IF irRight = 0 THEN GOSUB Run_Conveyor        ' if no object detected, continue running conveyor
  IF irRight = 1 THEN RETURN                    ' if object detected return to main

Comments

  • HumanoidoHumanoido Posts: 5,770
    edited 2011-01-27 19:40
    When the conveyor is running, the sensor needs more periodic checking in a loop so that it can stop when activated.
  • bee_manbee_man Posts: 109
    edited 2011-02-01 19:12
    Did you get this to work?
    Try

    Run_Conveyor:

    DO
    PULSOUT RMotor, RFWD ' turns conveyor motor on
    GOSUB Read_IR_Sensors_2 ' checks IR sensor #2
    IF irRight = 1 THEN RETURN ' if object detected return to main
    LOOP

    Let us know if that helps. I would also add a timer to stop the belt if an object is not detected in say 10 sec.

    Jim
Sign In or Register to comment.