trigonometryroboticskinematics

How to move a robot arm in a circle


I have a 6 joint robot arm, and I want to move it in a circle. I want parameters to choose the radius, degrees, and resolution/quality of the circle.

How do I do this?

arm


Solution

  • A quick trig review:

    The hypotenuse is opposite the right angle of the triangle.

    enter image description here

    The ratio of the height to the hypotenuse is called the sine.

    The ratio of the base to the hypotenuse is called the cosine.

    Generating (x,y) coordinates of a circle

    The circle is centered at the point (0,0). The radius of the circle is 1. Angles are measured starting from the x-axis. If we draw a line from the point (0,0) at an angle a from the x-axis, the line will intersect the circle at the point P.

    image

    To generate the coordinates along a circle, let's start with a small example. We'll use r to refer to the radius of the circle and a to refer to the angles spanned starting from the x-axis.

    Let's start with just the five following angles: 0, 90, 180, 270 and 360.

    (0 and 360 degrees are the same angle, which is on the positive x-axis).

    r = 1
    
    a = 0, 90, 180, 270, 360 (angles in degrees)
    

    Then, to generate the X and y coordinates along the circle, we use the following equations for each of the angles:

    x = r * cos(a)
    y = r * sin(a)
    

    These are the x and y coordinates calculated from the two equations above:

    (1, 0)
    (0, 1)
    (-1, 0)
    (0, -1)
    (1,0)
    

    Here's what that looks like on a graph:

    image

    In the above examples, we're only using 4 points, so it doesn't look much like a circle yet. However, if we use 17 points, we can see the coordinates are approaching a circular shape:

    image

    Here is a visualization of the math (sin cos wave):

    gif

    Here is the Arduino code for a circular movement:

    void moveCircle(float radius, float degrees, float resolution, bool direction)
    {
      for (float i = 0; i <= degrees; i += resolution)
      {
        // Get X and Y
        float X = radius * cos(i * DEG_TO_RAD);
        float Y = radius * sin(i * DEG_TO_RAD);
    
        if (direction)
        {
          // Move circle vertically
          moveTz(X);
          moveTy(Y);
        }
        else
        {
          // Move circle horizontally
          moveTx(X);
          moveZ(Y);
        }
      }
    }
    

    I recommend testing this code by creating a graph in Microsoft Excel to verify that the x y coordinates create a circle.