Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue calling robot.arm.move_pose([0.25, 0.03, 0.15, 0.0, 1.57, 0]) #1

Open
PVC-Pipe opened this issue Jul 13, 2022 · 6 comments
Open

Comments

@PVC-Pipe
Copy link

Occasionally if I wait for a couple minutes between running a pyniryo2 script on a separate Ubuntu 18.04 machine, I will get this error.

Traceback (most recent call last):
  File "basic_movement.py", line 5, in <module>
    robot.arm.move_pose([0.25, 0.03, 0.15, 0.0, 1.57, 0])
  File "/home/usr/.local/lib/python3.6/site-packages/pyniryo2/arm/arm.py", line 502, in move_pose
    _result = goal.wait(self.__action_timeout)
  File "/home/usr/.local/lib/python3.6/site-packages/roslibpy/actionlib.py", line 145, in wait
    raise Exception('Goal failed to receive result')
Exception: Goal failed to receive result

After trying to run the code a few more times, it will eventually succeed and pass through, but it's inconsistent.

@Jpl-niryo
Copy link

Hi,
This error sometimes occurs when the robot is connected via wifi and the connection is unstable. Have you tried using an ethernet cable to connect to the robot?
Cheers,
Jpl

@PVC-Pipe
Copy link
Author

PVC-Pipe commented Aug 4, 2022

The robot is connected via ethernet.

@Jpl-niryo
Copy link

Hi,
I tried to reproduce your error, but without much success. Would you be able to send me your entire code so I can try running it?
Also, be aware that Pyniryo2 is asynchronous which means that your movements can be overwritten by other commands in your code if you did not define a callback function. This may be the reason why you have your issue.

@PVC-Pipe
Copy link
Author

PVC-Pipe commented Aug 5, 2022

Here's the script that I'm currently running:

import argparse
import numpy as np
from pyniryo2 import *

ROBOT_IP = "robot_ip_address"

def main() -> None:
    # receive source and sink workspaces from the command line
    parser = argparse.ArgumentParser()
    parser.add_argument("source_workspace", action="store", type=str, help="workspace where the items are grabbed from")
    parser.add_argument("sink_workspace", action="store", type=str, help="workspace where the items are placed")

    args = parser.parse_args()

    source_workspace = args.source_workspace
    sink_workspace = args.sink_workspace

    # create a robot obj and initialize
    robot_ip_address = ROBOT_IP
    robot = NiryoRobot(robot_ip_address)
    robot.arm.calibrate_auto()
    robot.tool.update_tool()

    # calculate the observation pose
    workspace_poses = robot.vision.get_workspace_poses(source_workspace)
    x_values = [pose.x for pose in workspace_poses]
    y_values = [pose.y for pose in workspace_poses]
    x = (max(x_values) - min(x_values)) / 2 + min(x_values)
    y = (max(y_values) - min(y_values)) / 2 + min(y_values)
    phi = np.arctan2(y, x)
    short_rho = np.sqrt(x ** 2 + y ** 2) - 0.12
    x = short_rho * np.cos(phi)
    y = short_rho * np.sin(phi)

    source_observation_pose = PoseObject(
        x=x,
        y=y,
        z=0.3,
        roll=0.0,
        pitch=1.57,
        yaw=phi)

    # calculate the sink observation_pose
    workspace_poses = robot.vision.get_workspace_poses(sink_workspace)
    x_values = [pose.x for pose in workspace_poses]
    y_values = [pose.y for pose in workspace_poses] 
    x = (max(x_values) - min(x_values)) / 2 + min(x_values)
    y = (max(y_values) - min(y_values)) / 2 + min(y_values)
    phi = np.arctan2(y, x)
    short_rho = np.sqrt(x ** 2 + y ** 2) - 0.12
    x = short_rho * np.cos(phi)
    y = short_rho * np.sin(phi)

    sink_observation_pose = PoseObject(
        x=x,
        y=y,
        z=0.3,
        roll=0.0,
        pitch=1.57,
        yaw=phi)

    # move to observation pose
    robot.arm.move_pose(source_observation_pose)

    input_shape = ObjectShape.ANY
    input_color = ObjectColor.ANY

    # grab the input object
    obj, obj_shape, obj_color = robot.vision.vision_pick(source_workspace, 0.01, input_shape, input_color)
    
    while obj:
        if obj_shape == ObjectShape.SQUARE:
            x = (max(x_values) - min(x_values)) / 3 + min(x_values)
        elif obj_shape == ObjectShape.CIRCLE:
            x = 2 * (max(x_values) - min(x_values)) / 3 + min(x_values)
        
        if obj_color == ObjectColor.RED:
            y = (max(y_values) - min(y_values)) / 4 + min(y_values)
        elif obj_color == ObjectColor.GREEN:
            y = 2 * (max(y_values) - min(y_values)) / 4 + min(y_values)
        elif obj_color == ObjectColor.BLUE:
            y = 3 * (max(y_values) - min(y_values)) / 4 + min(y_values)

        place_pose = PoseObject(
            x=x,
            y=y,
            z=0.09,
            roll=0.0,
            pitch=1.57,
            yaw=1.57)

        robot.arm.move_pose(sink_observation_pose)
        robot.arm.move_pose(place_pose)
        robot.tool.release_with_tool()

        # move to observation pose
        robot.arm.move_pose(source_observation_pose)
        # grab the input object
        obj, obj_shape, obj_color = robot.vision.vision_pick(source_workspace, 0.01, input_shape, input_color)

    # end the robot
    robot.arm.move_to_home_pose()
    robot.end()

if __name__ == "__main__":
    main()

@Jpl-niryo
Copy link

Thank you for sending me the code. I do not see the line you are referring to however(move_pose([0.25, 0.03, 0.15, 0.0, 1.57, 0]))?
Also did you change the movement speed of the arm? If the movement is set to be really slow, the robot sometimes takes longer to reach it's goal than the timeout timer even though nothing is wrong.

@ValentinPitre
Copy link
Contributor

It's an known issue. It come from roslibpy library.
Try removing robot.end() at the end of your code, it might solve this problem :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants