How to rotate Doosan Robot head without going into errors

Because the robot can try to rotate outside the limit of 360 to -360 degrees and then generate a servo lock error where you need to unlock the servo manually and then restart the robot, you need to make functions to move the head rotations to the neutral position like homing it every time you want to rotate off. You can track the rotation of the head so it will not rotate past the max rotation.

def angleToAA(Angle):
    #Angle *= -1
    return posx(0, 0, 0, 0, 180, Angle)

head_angle = 180
def rotate_head_angle(Angle):
    global head_angle
    max_degrees = 360
    # min_degrees = -100
    min_degrees = 0
    arm_position, _i = get_current_posx()
    arm_position[3] = 0
    arm_position[4] = 0
    arm_position[5] = 0

    while (Angle > max_degrees):
        Angle = Angle - 360
    while (Angle < min_degrees):
        Angle = Angle + 360

    while (head_angle < Angle):
        head_angle += 90
        if (head_angle > Angle):
            head_angle = Angle
        movel(add_pose(arm_position, angleToAA(head_angle)), vel=30, acc=30)

    while (head_angle > Angle):
        head_angle -= 90
        if (head_angle < Angle):
            head_angle = Angle
        movel(add_pose(arm_position, angleToAA(head_angle)), vel=30, acc=30)
    return 0

This function remembers the head’s angle and then makes a waypoint in a direction the head can rotate. To use the function, you can use the example below. First, call the rotate_head_angle function. After that, use a model with the angleToAA function called with the same angle in degrees to move the robot.

rotate_head_angle(_Angle)

movel(add_pose(posx(_pos_x + x_offset, _pos_y + y_offset, _pos_z + _distance, 0, 0, 0), angleToAA(_Angle)), vel=velocity, acc=accelleration)

This was the end of this tutorial, I hope it helped you. Good luck with your project!

If you want to discuss this topic or if you have questions, reply in the comments.

Code Writen by A.Vonk

2 Likes