Code Monkey home page Code Monkey logo

spider's Introduction

Arduino library - Spider

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).

Beginning of work

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.

Eng

Library

The library contains 2 classes - "Legs" for separate control and characteristic of each leg and "Spider" which controls the whole robot's body.

Leg

#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).

Constructor

  1. Empty leg
  2. leg initialization during the creation
#include <Leg.h>

void setup() {
  Leg a();
  Leg b(15, 16, 17, 90, 130, 115, 'r');
}

Methods

  1. 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);
}
  1. setUpside (setting leg's side)
#include <Leg.h>

void setup() {
  Leg b(15, 16, 17, 90, 130, 115, 'r');
  b.setupSide('l');
}
  1. 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});
}
  1. 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();
}
  1. 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();
}

Spider

#include <Spider.h>

The class which connects all 6 spider's legs

Constructor

  1. Initialization of object using legs
  2. Using SpiderAdapter structure. This structure contains legs which then we can redefine into a spider
  3. 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.

Methods

  1. 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);
}
  1. 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);
}

spider's People

Contributors

dmkyr20 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.