Let's Make Robots!

PICAXE28x1, Sharp IR Sensor and Infrared sensor problems

Hi everyone,

 

I'm making a robot project for my mechatronics course and I am using picaxe28x1 with an infrared range sensor that I just copied from the Start Here post here at LMR. I did everything, and exactly the same set up like what the guy did. Howeve because we are required to make at least one of our own infrared circuit, I added an infrared sensor (with a transmitter and receiver circuit and a LED indicator) circuit together with the servo and the Sharp IR sensor. I did the set up and wrote my program but it's not doing the job.

Here's the program I wrote. can some one help me please to correct what is missing or which one I need to rectify in the program? From research on this site, it seems that problem in PWMOUT is common with picaxe and servo. Please advise. Thanks.

symbol RED = b.0

symbol PWMOUTPIN = 1

SYMBOL RECEIVEROUT = PINC.3

 

MAIN:

 

FORWARD A

FORWARD B

PWMOUT PWMOUTPIN, 25, 15

PAUSE 5

 

IF RECEIVEROUT = 0 THEN

               GOTO BEAMBROKEN

ELSE

               GOTO INFRARECEIVED

ENDIF

GOTO MAIN

 

 

BEAMBROKEN:

               LOW RED

               GOTO WHICHWAY

               GOTO MAIN

              

 

INFRARECEIVED:

               HIGH RED

               GOTO MAIN

              

 

WHICHWAY:

HALT A

HALT B

SERVO 1,75         'SERVO TO TURN RIGHT

PAUSE 500

readadc 0,b1

SERVO 1,225       'SERVO TO TURN LEFT

PAUSE 500

readadc 0,b2

SERVO 1,150       'SERVO TO LOOK STRAIGHT

PAUSE 500

DEBUG

 

if b1<b2 then

 goto body_lturn

else

 goto body_rturn

end if

goto main

 

body_lturn:

forward a

halt b

goto main

 

body_rturn:

forward b

halt a

goto main

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Sure, I will post pictures after an hour

 

basically what I want the robot to do is use the IR sensor to measure distance on the left and right side if in case there is an obstacle/wall he has to stop first and then decide which way to go depending on the readings. If both right and left readings doesn't indicate that there is a wall, the robot has to keep on driving forward. However, as he drive forward, the servo should continuously check both right and left side. The infrared circuit that I made will serve as the front sensor. If only we weren't required to make at least one I could use the IR sensor as a front sensor too but  I just thought I will just use the infrared circuit that I did to serve as a front sensor.

As mentioned, I will post pictures later for clarity.

Also, my teacher reckons something is in conflict with the pwmout command and the servo.

 

 

 

 

I did some changes to the program but still it's not doing what I want.

 

symbol RED = b.0
symbol PWMOUTPIN = 1
SYMBOL RECEIVEROUT = PINC.3

MAIN:

PWMOUT PWMOUTPIN, 25, 10
PAUSE 5

IF RECEIVEROUT = 0 THEN
 GOSUB BEAMBROKEN
ELSE
 GOSUB INFRARECEIVED
ENDIF
GOTO MAIN

 
BEAMBROKEN:
 LOW RED
 FORWARD A
 FORWARD B
 PAUSE 50
 RETURN

INFRARECEIVED:
 HIGH RED
 GOTO WHICHWAY
 RETURN

WHICHWAY:

HALT A
HALT B
SERVO 1,75 'SERVO TO TURN RIGHT
PAUSE 500
readadc 0,b1
SERVO 1,225 'SERVO TO TURN LEFT
PAUSE 500
readadc 0,b2
SERVO 1,150 'SERVO TO LOOK STRAIGHT
PAUSE 500
DEBUG

if b1<b2 then
 gosub body_lturn
else
 gosub body_rturn
end if
RETURN

body_lturn:
forward a
halt b
return

body_rturn:
forward b
halt a
return

I read this somwehere in LMR that servo and pwm command should not be use at the same time for picaxe28x1. how do I go abut this, rather how should I fix my program so that they are not running at the same time?

 

One poster wrote: You don't need to switch off a servo(pos) command. Any other timer command like pause should stop the servo(pos) command. Just add a line with pause 500 for instance. If you still have problems, please post the part of your code, which makes trouble :)

 

I am not too sure where to write the pause command in my program so as to make sure that the servo and pwm commands are not running at the same time.

The servo command and the PWM command share the same internal timer on the 28X1 so you can't mix the two. Changing the timing of one screws with the other. With the 28X2 they add another timer (timer2?) to the PWM mix and you can use both servos and PWM if you use the right pins. If you only need one (SERVO or PWMOUT) at any given time there are workarounds but you can't get both at the same time with the 28X1, sorry.