This library was created for simple Arduino projects with the use of Multiservo shield for controlling at the same time all 18 servos, which are parts of the robot's legs. Supposed, that the robot has 6 legs with 3 degrees of freedom each (meaning, that 3 servos are responsible for each leg's movement).
The library is designed for Multiservo shield and is based on their library. Therefore, it is necessary to download their library before starting the work. The library can be installed as shown below, previously downloading it as an archive.
The library contains 2 classes - "Legs" for separate control and characteristic of each leg and "Spider" which controls the whole robot's body.
#include <Leg.h>
As said, class "Leg" is used for controlling movements of robot's leg. Each leg is composed of 3 motors (hip - upper servo, knee -middle servo, foot - lower servo).
- Empty leg
- leg initialization during the creation
#include <Leg.h>
void setup() {
Leg a();
Leg b(15, 16, 17, 90, 130, 115, 'r');
}
- setupStaticAngle (setting standard angles for the leg)
#include <Leg.h>
void setup() {
Leg b(15, 16, 17, 90, 130, 115, 'r');
b.setupStaticAngle(90, 130, 115);
}
- setUpside (setting leg's side)
#include <Leg.h>
void setup() {
Leg b(15, 16, 17, 90, 130, 115, 'r');
b.setupSide('l');
}
- moving (putting the leg in a specific position with the help of Angle structure). Angle structure is made up of 3 angles (1 angle for each servo).
#include <Leg.h>
void setup() {
Leg b(15, 16, 17, 90, 130, 115, 'r');
// const Angle LEG_UP = {1, 60, 70}; - Стандартная константа
b.moving(LEG_UP);
b.moving({1, 60, 70});
}
- getCurrentAngle (getting back the angle in which leg is at the moment)
#include <Leg.h>
void setup() {
Leg b(15, 16, 17, 90, 130, 115, 'r');
// const Angle LEG_DOWN = {1, -30, 70}; - Стандартная константа
b.moving(LEG_DOWN);
Angle a = b.getCurentAngle();
}
- get StaticAngle (getting back standard leg's angle)
#include <Leg.h>
void setup() {
Leg b(15, 16, 17, 90, 130, 115, 'r');
// const Angle LEG_DOWN = {1, -30, 70}; - Стандартная константа
b.moving(LEG_DOWN);
Angle a = b.getStaticAngle();
}
#include <Spider.h>
The class which connects all 6 spider's legs
- Initialization of object using legs
- Using SpiderAdapter structure. This structure contains legs which then we can redefine into a spider
- Object's creation
#include <Spider.h>
Spider mySpider;
void setup() {
Leg rightTop(15, 16, 17, 90, 130, 115, 'r');
Leg leftTop(2, 1, 0, 90, 55, 60, 'l');
Leg rightCenter(12, 13, 14, 95, 130, 130, 'r');
Leg leftCenter(5, 4, 3, 90, 50, 40, 'l');
Leg rightBottom(6, 7, 8, 90, 130, 90, 'r');
Leg leftBottom(9, 10, 11, 90, 40, 50, 'l');
mySpider = Spider(leftTop, leftCenter, leftBottom, rightTop, rightCenter, rightBottom);
}
Warning: Be careful - during the legs' creation copies of elements are transmitted, not their links. Therefore, you have to make sure that you erase all extra legs' objects if they are already written in the Spider.
- setLegs (installing legs)
#include <Spider.h>
Spider mySpider;
void setup() {
Leg rightTop(15, 16, 17, 90, 130, 115, 'r');
Leg leftTop(2, 1, 0, 90, 55, 60, 'l');
Leg rightCenter(12, 13, 14, 95, 130, 130, 'r');
Leg leftCenter(5, 4, 3, 90, 50, 40, 'l');
Leg rightBottom(6, 7, 8, 90, 130, 90, 'r');
Leg leftBottom(9, 10, 11, 90, 40, 50, 'l');
mySpider = Spider(leftTop, leftCenter, leftBottom, rightTop, rightCenter, rightBottom);
mySpider.setLegs(leftTop, leftCenter, leftBottom, rightTop, rightCenter, rightBottom);
}
- moving (takes Mover structure as an argument. This structure keeps inside all angles for each leg)
#include <Spider.h>
Spider mySpider;
void setup() {
Serial.begin(9600);
Leg rightTop(15, 16, 17, 90, 130, 115, 'r');
Leg leftTop(2, 1, 0, 90, 55, 60, 'l');
Leg rightCenter(12, 13, 14, 95, 130, 130, 'r');
Leg leftCenter(5, 4, 3, 90, 50, 40, 'l');
Leg rightBottom(6, 7, 8, 90, 130, 90, 'r');
Leg leftBottom(9, 10, 11, 90, 40, 50, 'l');
mySpider = Spider(leftTop, leftCenter, leftBottom, rightTop, rightCenter, rightBottom);
}
void crouch(int del = 200) {
mySpider.moving(MOVE_CROUCH);
delay(del);
mySpider.moving(MOVE_STANDUP);
}