Singapore
Asked — Edited
Resolved Resolved by Rich!

Reaction And Movement Of Robot

Hi Everyone,

I would like to enquire if the EZ-Script is able to program the robot in such a way that..

  1. Detect red/green object
  2. Move towards the object
  3. Stop before the object (Around 3-5cm where it will be able to grab hold of the object)

Is it possible? I would have to use the multi-color detection for detecting both colors (Red and Green).

Thanks and would really hope to receive a reply soon. :)


ARC Pro

Upgrade to ARC Pro

Unleash your creativity with the power of easy robot programming using Synthiam ARC Pro

#1  

Yes, it is possible. Also, it may work better if you use a sharp IR detector at close range.

my 2 cents.

#2  

This is very easy and no problem for the EZB and camera.... Dj's Wall-e video demonstrates it quite well

#3  

You'll want to use the Camera enable movement tracking


controlcommand("camera", cameramovementtrackenable)

ChaseandGripGreen.EZB

Attached is an ezb file I made to use the camera with a script to track the color of green object and my robot RedBender's gripper grabs it once it is reached. Obviously change the ports values to match your robot's configuration.

For my usage it stops when the object is in range of the gripper and the gripper closes. For a more specific range you'd want to integrate sonar distance sensor. Because the camera can (to my knowledge) only be used to sense when an object is in a certain grid, but not give a distance.


Ping_Wait(D8, D9, LOWER, 5)

This would wait to take action until the ping shows a distance lower than 5. Again, chance d8 and d9 to reflect your port values.

Singapore
#4  

Hi, Thanks all for the replies! Appreciate it much!

@JustinRatliff May I ask what does this sentence of code means? If ($CameraVerticalQuadrant = "Middle")

United Kingdom
#5  

$CameraVerticalQuadrant is the variable for the camera which states which section of the image the object is within. By using the "Middle" it is checking if the vertical position on the camera is in the middle vertically.

Singapore
#6  

@Rich but what will be the purpose of this line of code when using camera to track the object? Pardon me for my slow understanding.

Singapore
#7  
Servo(d2, 70)

controlcommand("camera", cameramovementtrackenable)

:loop

If ($CameraVerticalQuadrant = "Middle")
controlcommand("camera", cameramovementtrackdisable)
Servo(d2, 40)
sleep(9000)
EndIf

goto(loop) 

If the script goes line by line, does this mean that the servo D2 will be position at position 70 first before enabling the camera movement track. Next, it will be a loop for which, it will be tracking until the object is in the middle of the camera and that when the camera movement will be disable and the servo D2 will be lower to position 40 to pick the object up?

PS. If I got this wrongly.

United Kingdom
#8  

Following that code snippet it would;

Move the servo connected to D2 into position 70 Enable the movement tracking of the camera Check for where the movement is detected If it is the middle vertically it will disable the movement tracking then move the servo connected to D2 into position 40 Wait for 9 seconds and then loop back If it isn't vertically it will just loop back It will then repeat the IF nest.

However, if the condition is met the tracking is disabled, it will then constantly loop checking for the position on a disabled camera. There is no escape routine from that loop.

United Kingdom
#10  

It wouldn't load or you couldn't download it?

There is a problem with the link but it should be available here (took a bit of finding since the user details pages are also slightly broken too - a bug that has been reported previously).

Singapore
#11  

@Rich Does this script work this way?


Servo (D2, 70)
ControlCommand("Camera", CameraStart)

IF ($CameraIsTracking = 1)
  ControlCommand("Camera", CameraMotionTrackingEnable)
  
  :loop
  IF ($CameraVerticalQuadrant = "Middle")
    ControlCommand("Camera", CameraMotionTrackingDisable)
    ControlCommand("Camera", CameraMultiColorTrackingEnable)
    
    # Custom Color = Red
    IF ($CameraObjectColor = "Custom Color")
      SayEZB("There is a red object.")
      Move (D9, forward)
      Move (D12, forward)
      Move (D9, stop)
      Move (D12, stop)
      
      # open left gripper
      servo (D4, 150)
      # Lower Left Arm
      servo (D2, 40)
      # Close Left Gripper
      servo (D4, 30)
      
      # Color 2 = Green
    ELSEIF ($CameraObjectColor = "Green")
      SayEZB("There is a green object.")
      Move (D9, forward)
      Move (D12, forward)
      Move (D9, stop)
      Move (D12, stop)
      
      # open right gripper
      servo (D7, 150)
      # Lower Right arm
      servo (D5, 40)
      # Close right gripper
      servo (D7, 30)
    ENDIF 
      
    sleep(9000)
  ENDIF 
    
  Goto(loop)
  
ELSEIF ($cameraistracking = 0)
  SayEZB("I cannot see anything")
ENDIF 

Move the servo connected to D2 into position 70 [D2 is the left arm] Camera will start

It will enable the movement tracking if the camera is tracking. THEN :loop will be the start of the loop

If the image is vertical in the middle, the movement tracking will be disable, and the multicolor tracking will be enable.

(Ps because I do not have the camera rolling yet, so the name 'Custom Color' is Red) If the object is red, the servo D9 and D12 will be moved forward and stop before the object after which, it will then open D4 (which is the gripper) to position 150 then Move the servo connected to D2 into position 40 (to lower from position 70), D4 will then be close back to position 30.

Same for the green object, however, left arm will be used to pick up red object and right arm will be used to pick up green object.

Wait for 9 seconds and then loop back If it isn't vertically it will just loop back It will then repeat the IF nest.

Ps. Is my EZ-Script correct? The flow I wanted was to: Use the camera to track the environment and then detect the object. Next, move towards the object then pick up using either left or right arm depending on whether it is red or green in color.

Thank you very much. :)

United Kingdom
#12  

I only had chance to quickly scan over it but I think you've got the main idea.

One thing I noticed though,

      Move (D9, forward)
      Move (D12, forward)
      Move (D9, stop)
      Move (D12, stop)

This will not do anything, well, not for very long anyway. Almost immediately after moving the servos forwards it stops them. I didn't have chance to see what you are attempting to achieve so can't advise too well but either a sleep() to let it move forward for a set time or a WaitForChange() (or similar) to let it move until an event happens between the forward and stop commands should work.

When I get home I'll look properly. To be honest I don't think EZ-Script is needed since there are built in controls that may do it all for you, or at least the main parts. But I'll have a look later and post some more advice etc. :)

Singapore
#13  

@Rich Thanks for the reply! Roughly what I want to do is that, the robot will be able to detect the red/green object, and move towards that and after which pick the object up depending on which color. (left hand pick red object, right hand pick green object)

Looking forward to your guidance! ;)

United Kingdom
#15  

Sorry, I haven't forgotten this I just haven't had chance to sit down with ARC and check it out properly - I will.