ARC Pro

Upgrade to ARC Pro

Unlock the true power of automation and robotics by becoming a proud subscriber of Synthiam ARC Pro.

#2  

Thanks Bob, I will have a look. What I'm hoping, when the script is ran and it only needs to go left to avoid an object it goes back to forward without having to run left, reverse etc. or the rest of the script, hope that make sense.

#3  

After going though Rich's post I got it to work only using the below script. However, it always reverses before going left or right. Alarm1 should only reverse if all 3 ping sensors are lower then 45, but if 1(right) or 2 (left) ping sensors get below 45 it reverses then goes right or left depending on which side of the sensor is below 45. I only want it to reverse if all 3 (L,C,R) ping sensors are tripped.

Can someone without taking to much time explain what I am missing? This is just a simple script and I am so it could get pretty involved so I just want a simpleton script. Cheers,



:sensorcheck
$proxclose =45  # Change for minimum distance
$proxsideclose = 45 #Change for minimum distance

$proxbaseC = GetPing(3.D22,3.D23)
$proxbaseR = GetPing(3.D15,3.D14)
$proxbaseL = GetPing(3.D13,3.D12)
$proxsideL = GetPing(3.D10,3.D11)
$ProxsideR = GetPing(3.D16,3.D17)


# If 3 ping sensor >45 go forward
if($proxbaseC > $proxclose or $proxbaseL > $proxclose or $proxbaseR > $proxclose)
  goto(Clear) 
  
  

#If 3 ping sensors <45 stop and reverse
elseif($proxbaseC < $proxclose or $proxbaseL < $proxclose or $proxbaseR < $proxclose)
  goto(Alarm1)


# if 3 front ping sensors Center and left less <45 
elseif($proxbaseC < $proxclose or $proxbaseL < $proxclose and $proxbaseR > $proxclose and $proxsideR > $proxsideclose)
goto (AlarmR)



#if 3 front ping sersors center and right < then
elseif($proxbaseC < $proxclose or $proxbaseR < $proxclose and $proxbaseL > $proxclose and $proxsideL > $proxsideclose)
goto (AlarmL)
endif


goto(sensorcheck)

:Alarm1
#if ($pingFR < 40)
Say("Object Detected")
Stop()
Reverse(255,2000)
Sleep(1000)
Return()

:AlarmR
#if ($pingFL < 40)
Say("Object Detected")
Stop()
Right(255,2500)
sleep(2000)
return()

:AlarmL
#if ($pingFL < 40)
Say("Object Detected")
stop()
Left(255,2500)
sleep(2000)
Return()

:Clear
#if ($pingFL > 60)or ($pingFR > 60)
Say("No Object Detected")
Forward()
Sleep(500)
Return()



#Halt()

#4  

Well I tried it one more time and all 3 sensors coved and it did reverse, but then it goes to right and left before going forward again. I don't know what I am doing wrong. stress

#5  

Just giving the code a quick once over, I see you have used "or" conditionals when you should have used "and"

For example given the comment: # If 3 ping sensor >45 go forward To me this says "Only If ALL of the 3 ping sensors are greater than 45, then go forward." But what you have actually coded currently says "If ANY of the 3 ping sensors are greater than 45, go forward". You need to change the "or" conditionals to "and" The same for the other statements as well. They should all be ands, not ors.

There are some other issues as well, but I won't go into them until we see how these changes work out.

#6  

Sweet! @WBS00001 that worked, thank you.
if all 3 sensors are close it reversed, if right and center sensors are close, it turned like it should:) . I noticed if only the right sensor is close nothing happens and continues forward. So I must need to add more elseif statements, is this correct?

I am now a happier camper:D You mentioned there are other issues? Thanks again.

#7  

WBS00001 Did solve my issue and thank for your quick reply. Hope you offer more advise. Cheers!

#8  

Very good! Glad that helped. Before I can advise further I will need some information.

Now that I have had time to look at the code more closely, it appears the Ping Sensor configuration is 3 pointing forward on the base (Left, Center, and Right) and there are two sensors on the left and the right for a total of 5. Is this correct?

Assuming it is then I was wrong in telling you to change the "or" conditionals to "and" types in the ElseIf statements. The ElseIf statements should be put back the way they were. However, changing the conditionals to "and" type in the first (If) statement is still correct. You only want to move forward if all 3 front facing sensors are clear.

I see the 4 If-ElseIf statements saying the following:

  1. If ALL 3 front Ping Sensors are returning clear (nothing close to them), move forward.
  2. ElseIf ANY of the Base Sensors detect something close, stop and reverse.

As I said above, here I can see now that the conditionals in this first ElseIf statement should have been left as they were. Sorry I didn't realize that last night. In fact all the ElseIf statements should be put back to the way they were.

Continuing on with the ElseIfs back to how they were then: 3) ElseIf the Center Base Sensor OR the Left Base Sensor detects something close, AND the Right Base Sensor is clear AND the Right Side Sensor is Clear, then Turn Right. This is to avoid obstacles ahead towards the Left.

  1. ElseIf the Center Base Sensor OR the Right Base Sensor detects something close, AND the Left Base Sensor AND the Left Side Sensor are clear, then turn Left. This is to avoid obstacles ahead towards the Right.

These states should also take into account if the unit is heading for the right or left wall, but only if it is heading that way at an angle.

Another question I have is what are the variables $pingFL and $pingFR? When are they set to some value?

As it stands now, I think the unit will go in a zig-zag pattern as it avoids obstacles. That is not a bad thing, just that it appears it will go all the way from wall to wall as it avoids things instead of turning from an obstacle and going back straight again. I'll have to give that more thought, however.

There may be an additional problem with the first ElseIf statement. I will need to run some tests to be sure. After I do, I will post again.