Australia
Asked — Edited

Turning By Us (Ultra Sonic)

Hello,

Forgive my newby question, but I am attempting to make my robot a little smarter at turning that just turn for x mseconds.

Below is my adaptation of one of the sample scripts, but what I really want to do is if object A is 30 in front turn to a clear side until object A is> 120, then rescan and proceed forward.

What I cant work out is how to give a turn (left or right) command based on a US signal value increasing in value to a designated "ok to proceed" value. I have the which way to turn done, but not turn for how much.

Any Help would be greatly apreciated.

Set the servo left position

$PosL = 90

Set the servo center position

$PosC = 50

Set the servo right position

$PosR = 30

Set the mininum distance

$MinDist = 30 $SlowDist = 100 $RDMin = 50

:Loop

Begin Scanning IO

Middle Stationary US

$PingMid = GetPing(d2, d3)

Scan left

Servo(d7, $PosL) Sleep(500) $PingL = GetPing(d0, d1)

Scan Center

Servo(d7, $PosC) Sleep(500) $PingC = GetPing(d0, d1)

Scan Right

Servo(d7, $PosR) Sleep(500) $PingR = GetPing(d0, d1)

#Begin Move

if ($PingMid $PingL) $Ping1 = $PingR endif If ($Ping1 < $MinDist) Reverse(255, 1000) Elseif ($Ping1 < $PingL) Right (255,1000) Else Left (255,500) Endif forward(20) Return()

:RightBad left(255, 500) sleep(1000) Forward() Return()


ARC Pro

Upgrade to ARC Pro

Unleash your robot's full potential with the cutting-edge features and intuitive programming offered by Synthiam ARC Pro.

Australia
#9  

Hi Rich, I like your escape routing, I was wondering if you can put a goto within a goto until result = different,

Thanks for the info, I was also thinking that the finished product is going to need 3 sensors for my robot, but on the iRobot scooba a sweep would be fine as it travels very slow.

Do you know if there is a PID type control loop function in Ez, in a plc I would use this function to have a setpoint, and then give values to the P and I so the output would adjust continuously until the output matches the setpoint.

In my wall hug I was thinking of using two sensors front and rear, and have a setpoint of say 10 (distance from the wall) because one is at the front and one is at the rear I could then use logic to speed up or slow the outer wheel to maintain the Setpoint (10) away from the wall.

Next I would need a counter, so when the robot gets to the end of the room it would turn 90 deg, move the width of the robot, then turn 90 again. then progress on a new path were the setpoint is now setpoint +1 the +1 being the width of the robot. The counter would store the 90 degree turns and thus tell me how much the + value should be.

Anyway again thanks for all your help.

Ghost

United Kingdom
#10  

A goto in a goto doesn't make sense but I think I know what you mean. Like;


:loop
If($x &lt; $y)
  Goto(process1)
Else
  Goto(loop)
EndIf

:process1
If($a &gt; $b)
  Goto(process1)
ElseIf($a&lt;$b)
  Goto(loop)
Else
  Goto(process2)
EndIf

:process2
If($x &gt; $y and $a &lt; $b)
  Goto(selfdestruct)
EndIf
Return()

:selfdestruct
# Kaboom!

Obviously that code does nothing but if that's what you mean by having a goto in a goto then yes you can.

PID, so 2 results that need to meet the third? Like;


If($p = $d and $i = $d)
  Goto(success)
Else
  Goto(fail)
EndIf

Or have I interpreted it incorrectly?

Australia
#11  

Hi Rich, I was referring to your code were one of the IF results in going back to the top of the "goto() that it is already in

A snippet from your code. :detect IF ($onlyforward = 1) IF ($Direction = "Forward") GOTO (detectstart) ELSE GOTO (detect) <---------------------------------- ENDIF ELSE

I didnt know you could do this and it will make my code a lot simpler in some places and help greatly with my turn by ping code.

On the PID - Yep totally missed it. Although your answer is probably the way I am going to have to deal with it.

A PID is block of logic, that you give a set-point to the P is the gain or rate at which the output is changed trying to the set-point. Inevitably it over shoots some as it is always trying to correct. So some smart engineer invented the I part or integral which is repeats of outputs per period X this over comes the over shoots by making minute repeated adjustments until the output meets the input. This is used in PLC for flow control temp control, pressure control etc of processing plants, most logic controller I have ever had to deal with have this functionality and thus I am used to being able to call a PID block plug in the IO points and the three PID values and have it do its job. .... Wishfull thinking I guess

It could be done with an if statement but it would need to be running all the time cycling as quick as possible.

regards Ghosty

United Kingdom
#12  

Ah yes, if only I had remembered that code I could have saved typing out the example above.

That part of the code works perfectly. When the variable for only when moving forwards is set to 1 it just loops around the IF statement until it is true. I could have done it a different way, with a WaitForChange on the direction variable but I don't think that command existed when I was writing it, plus I prefer this way personally.

The PID IF statement could be run as a separate script always running. Variables are global so $x in script y is also $x in script z.

So 2 scripts, one with the PID IF statement;


:loop
If($d = $p and $d = $i)
  # Do whatever if it fails
  ControlCommand(&quot;success&quot;,ScriptStart)
  $success = 1
Else
  # Do whatever if it fails
  ControlCommand(&quot;failed&quot;,ScriptStart)
  $success = 0
EndIf
Goto(loop)

That script will run pretty darn fast.

Then in the script that finds P & I have them set the variables, check the $success variable, run a third, fourth, fifth script, whatever needs to happen.

I've not hit a limit on how many scripts can be running at the same time and I run a lot of them at the same time on Melvin. Some interact with each other, others are stand alone.

United Kingdom
#13  

Just a heads up if you plan to reference the script I linked to, I'm having a slight nightmare getting it to work, somewhere there is a bug which is preventing it from looping forever. Something I am trying to figure out, it may be I am trying something that is not supported, I don't know.

However, feel free to attempt to debug it for me (set $testmode to 1 in the options if you don't have a robot that will work and it'll grab random numbers for the ping sensor readings - it's how I test scripts while not at home). I think it's a problem with the returns but not 100% sure and not focused enough to follow it all through at the moment.

Ignore the script manager, that's another plan I'm playing with.

FYI, the script now checks the last move and the penultimate move, if it has moved left then right and wants to move left again, or right then left and wants to move right again it wont, it'll run the escape code so it has a clear path in front of it. But as there is a bug in the code I've not seen how well this works.