Skip to content

Commit

Permalink
quad and ninja blocks with code
Browse files Browse the repository at this point in the history
  • Loading branch information
cparrapa committed Nov 8, 2021
1 parent ab8b804 commit 14a170e
Show file tree
Hide file tree
Showing 7 changed files with 783 additions and 371 deletions.
42 changes: 17 additions & 25 deletions compilation/arduino/userlibs/libraries/Quad/Quad.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
#include <EEPROM.h>
#include "Quad.h"

#define __LOAD_TRIM_FROM_EEPROM__
#define EEPROM_MAGIC 0xabcd
#define EEPROM_OFFSET 2 //eeprom starting offset to store trim[]
/*
(servo index, pin to attach pwm)
__________ __________ _________________
|(3,9)_____)(1,8) (0,2)(______(2,3)|
|(3,FLL)_____)(1,FLH) (0,FRH)(______(2,FRL)|
|__| |left FRONT right| |__|
| |
| |
| |
_________ | | __________
|(7,7)_____)(5,6)______(4,4)(______(6,5)|
|(7,BLL)_____)(5,BLH)______(4,BRH)(______(6,BRL)|
|__| |__|
*/
//comment below manually setting trim in Quad() constructor
#define __LOAD_TRIM_FROM_EEPROM__
#define EEPROM_MAGIC 0xabcd
#define EEPROM_OFFSET 2 //eeprom starting offset to store trim[]

// FRONT_RIGHT_HIP servo 0 Pin 2
// FRONT_LEFT_HIP servo 1 Pin 8
// FRONT_RIGHT_LEG servo 2 Pin 3
Expand All @@ -27,34 +26,26 @@
// BACK_LEFT_HIP servo 5 Pin 6
// BACK_RIGHT_LEG servo 6 Pin 5
// BACK_LEFT_LEG servo 7 Pin 7
Quad::Quad():/* reverse{0, 0, 0, 0, 0, 0, 0, 0}, */trim{0, 0, 0, 0, 0, 0, 0, 0} {
board_pins[FRONT_RIGHT_HIP] = 2; // front left inner
board_pins[FRONT_LEFT_HIP] = 8; // front right inner
board_pins[BACK_RIGHT_HIP] = 4; // back left inner
board_pins[BACK_LEFT_HIP] = 6; // back right inner
board_pins[FRONT_RIGHT_LEG] = 3; // front left outer
board_pins[FRONT_LEFT_LEG] = 9; // front right outer
board_pins[BACK_RIGHT_LEG] = 5; // back left outer
board_pins[BACK_LEFT_LEG] = 7; // back right outer
}

void Quad::reverseServo(int id) {
if (reverse[id])
reverse[id] = 0;
else
reverse[id] = 1;
}
void Quad::init(int Buzzer) {
//Buzzer & noise sensor pins:
void Quad::init(int FRH, int FLH, int FRL, int FLL, int BRH, int BLH, int BRL, int BLL) {


//Buzzer & noise sensor pins:
pinBuzzer = Buzzer;
//pinMode(NoiseSensor,INPUT);
board_pins[0] = FRH; // front left inner
board_pins[1] = FLH; // front right inner
board_pins[2] = FRL; // back left inner
board_pins[3] = FLL; // back right inner
board_pins[4] = BRH; // front left outer
board_pins[5] = BLH; // front right outer
board_pins[6] = BRL; // back left outer
board_pins[7] = BLL; // back right outer

/*
trim[] for calibrating servo deviation,
initial posture (home) should like below
in symmetric
trim[] for calibrating servo deviation, initial posture (home) should like below in symmetric
\ / front left
\_____/
| |->
Expand Down Expand Up @@ -95,6 +86,7 @@ void Quad::init(int Buzzer) {
home();

}

void Quad::attachServo(){
for (int i = 0; i < 8; i++) {
servo[i].attach(board_pins[i]);
Expand Down
5 changes: 2 additions & 3 deletions compilation/arduino/userlibs/libraries/Quad/Quad.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ extern "C" void pause(int);
class Quad {

public:
Quad();
void init(int Buzzer);
void init(int FRH, int FLH, int FRL, int FLL, int BRH, int BLH, int BRL, int BLL);
void home();
void run(int dir = 1, float steps = 4, float T = 550);
void walk(int dir = 1, float steps = 4, float T = 550);
Expand Down Expand Up @@ -61,7 +60,7 @@ class Quad {
bool reverse[8];
int EEPROMReadWord(int p_address);
void EEPROMWriteWord(int p_address, int p_value);
int pinBuzzer;

};

#endif
Loading

0 comments on commit 14a170e

Please sign in to comment.