We revive the hexapod. Part three

As practice has shown, the abundance of code in the article does not affect its readability very well. But to understand how it all works, it sometimes costs to strain your brains. What the previous publication was aimed at. Today I will try to complete a series of articles on the hexapod software stuffing by giving a brief overview of what we did not have time to meet.

The cycle of previous articles:


How we printed the hexapod and what came of
it. We revive the hexapod. Part One
We revive the hexapod. Part two

Configuration


The physical characteristics of the robot are defined in the program as a set of configuration parameters and transferred to a separate configuration file config.h . Among these parameters, the following main groups can be distinguished:

Sizes of limbs and features of their movement
IdentifierFeature Description
COXA_LENGTHShoulder length (mm)
FEMORA_LENGTH()
TIBIA_LENGTH()
TIBIA_OFFSET()
COXA_ANGLE_0()
FEMORA_ANGLE_0()
TIBIA_ANGLE_0()
COXA_ANGLE_INVERSE
FEMORA_ANGLE_INVERSE
TIBIA_ANGLE_INVERSE


The location and orientation of the limbs of the robot relative to its center
LEFT_FRONT_FOOT_POSITION
LEFT_MIDLE_FOOT_POSITION
LEFT_BACK_FOOT_POSITION
RIGTH_FRONT_FOOT_POSITION
RIGTH_MIDLE_FOOT_POSITION
RIGTH_BACK_FOOT_POSITION
LEFT_FRONT_FOOT_ROTATION
LEFT_MIDLE_FOOT_ROTATION
LEFT_BACK_FOOT_ROTATION
RIGTH_FRONT_FOOT_ROTATION
RIGTH_MIDLE_FOOT_ROTATION
RIGTH_BACK_FOOT_ROTATION


Permissible angle ranges for servo drives
COXA_MIN_ANGLE
COXA_MAX_ANGLE
FEMORA_MIN_ANGLE
FEMORA_MAX_ANGLE
TIBIA_MIN_ANGLE
TIBIA_MAX_ANGLE
COMPLEX_ANGLE_LIMITS_1
MIDLE_COXA_MIN_ANGLE
MIDLE_COXA_MAX_ANGLE


Robot movement characteristics
MOTION_JOB_PERIOD()
MOVE_STEP()
ROTATE_STEP()


Mathematics


To calculate the forward and reverse kinematics of the robot, vector and matrix calculations are required. This is done using the Vector3D and Matrix3D classes declared in 3d_math.h

struct Vector3D
struct Vector3D {
  float x,y,z;

  Vector3D operator -(void) {
    return {-x, -y ,-z};
  }                        

  Vector3D& operator=(const Vector3D a);
  
  float len();
};


struct Matrix3D
struct Matrix3D {
  float a[3][3];

  Vector3D operator *(Vector3D& v) {
    Vector3D p;
    p.x = v.x*a[0][0] + v.y*a[0][1] + v.z*a[0][2];
    p.y = v.x*a[1][0] + v.y*a[1][1] + v.z*a[1][2];
    p.z = v.x*a[2][0] + v.y*a[2][1] + v.z*a[2][2];
    return p;
  };                                               

  Matrix3D operator *(Matrix3D m) {
    Matrix3D r;
    for(int i=0; i<3; i++) {
      for(int j=0; j<3; j++) {
        r.a[i][j] = 0;
        for(int k=0; k<3; k++)
          r.a[i][j] += a[i][k]*m.a[k][j];
      }
    }
    return r;
  };
};

Operator overloading and helper functions
Vector3D operator +=(Vector3D left, const Vector3D right);
Vector3D operator -=(Vector3D left, const Vector3D right);
Vector3D operator- (Vector3D a, Vector3D b);
Vector3D operator+ (Vector3D a, Vector3D b);
Vector3D operator* (Vector3D a, Vector3D b);
Vector3D operator* (float a, Vector3D b);
Vector3D operator* (Vector3D a, float b);
Vector3D operator/ (Vector3D a, int b);
//        r = {rx, ry, rz}
Matrix3D rotMatrix(Vector3D r);  //   
Matrix3D rotMatrix2(Vector3D r);  //   
//  
float arcctn(float);


Source code


All source files are now available on GitHub . There you can find the draft application for Android and models for 3D printing. The arduino section consists of two sections:

  • main - the main set of files for the Arduino controller
  • wifi - firmware for esp8622 needed to organize a communication channel over Wi-Fi

What's next?


Despite the fact that this article is of a final nature, the topics of organizing a communication channel via Wi-Fi and control via Android have remained out of sight. If these topics are of interest or other unresolved issues remain, write about this in the comments or personal correspondence. I will definitely try to give a detailed answer or devote a separate article to this.

The Geksa project will continue its development. In the near future, it is planned to change the composition of electronic components, expand the functionality, finalize the robot body, make software additions. I will be glad to hear from you constructive comments or suggestions.

Thank!

All Articles