cobotta camera (EVP2)
When using CobottaCtrl directly in local mode, always call disconnect() on exit, including after an exception or KeyboardInterrupt.
Calibration
The coordinates of the point indicated in the camera image must be aligned with the robot coordinate system.
Simple example
from cobotta2 import Config, CobottaCtrl, MotionMode
Config.load_yaml("config_cobotta2.yaml")
logger = XLogger(log_level="info", logger_name=Config.CLIENT_LOGGER_NAME)
cobotta = CobottaCtrl(cobotta_ip=Config.COBOTTA_IP, arm_name="Arm", logger=logger)
try:
cobotta.reset_error()
# Number of objects recognized by the camera (used to determine success)
cobotta.I2 = 0
# Work coordinates that receive the camera recognition result
# Save the current position as a safe initial position
cobotta.P10 = cobotta.get_current_position()
# take_script() and take_camera() are mutually exclusive
# Release the arm before take_camera() if take_arm() was called
cobotta.release_arm()
while True:
logger.info("---------- カメラで画像認識 -------------------")
# Select the recognition model created with EVP2 Guidance
evp_script_name = "try_camera"
# The filename EVP2_03.pcs is arbitrary, but may overwrite an existing COBOTTA script
cobotta.take_camera(evp_script_name, "EVP2_03.pcs")
cobotta.run_script()
cobotta.wait_for_complete()
logger.info(f"Result(num): {cobotta.I2}")
if cobotta.I2 == 1:
break
logger.error(f"*** ターゲットが見つけられません ***")
logger.error(f"*** 3sec 後に retry します ***")
time.sleep(3)
logger.error(f"***")
logger.info(f"Result(pos): {cobotta.P10}")
logger.error(f"***")
logger.info("----------- 画像認識のセンターへmove --------------")
cobotta.take_arm()
cobotta.move("P10", motion_mode=MotionMode.LINE, offset=(0,0,0), path_blend="@E", speed=50)
cobotta.wait_for_complete()
except KeyboardInterrupt as e:
logger.error(e)
except Exception as e:
loggger.error(e)
finally:
cobotta.disconnect()