From 34ca1c5e01a3dcab1ad92e67a296938fd1c15c7e Mon Sep 17 00:00:00 2001 From: Lars H Date: Mon, 20 Nov 2017 12:38:27 +0100 Subject: [PATCH] New Code / Cleanup --- Zowi.cpp | 116 ------------------------------------------------------- Zowi.h | 42 -------------------- 2 files changed, 158 deletions(-) delete mode 100644 Zowi.cpp delete mode 100644 Zowi.h diff --git a/Zowi.cpp b/Zowi.cpp deleted file mode 100644 index f64b40e..0000000 --- a/Zowi.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include "Zowi.h" -#include - -void Zowi::init(int YL, int YR, int RL, int RR, bool load_calibration) { - servo[0].attach(YL); - servo[1].attach(YR); - servo[2].attach(RL); - servo[3].attach(RR); - - if (load_calibration) { - for (int i = 0; i < 4; i++) { - int servo_trim = EEPROM.read(i); - if (servo_trim > 128) servo_trim -= 256; - servo[i].SetTrim(servo_trim); - } - } - Serial.begin(115200); - Serial.println(" test"); - - for (int i = 0; i < 4; i++) servo_position[i] = 90; -} - -void Zowi::setTrims(int YL, int YR, int RL, int RR) { - servo[0].SetTrim(YL); - servo[1].SetTrim(YR); - servo[2].SetTrim(RL); - servo[3].SetTrim(RR); -} - -void Zowi::saveTrimsOnEEPROM() { - for (int i = 0; i < 4; i++) EEPROM.write(i, servo[i].getTrim()); -} - -void Zowi::moveServos(int time, int servo_target[]) { - if(time>10){ - for (int i = 0; i < 4; i++) increment[i] = ((servo_target[i]) - servo_position[i]) / (time / 10.0); - final_time = millis() + time; - - for (int iteration = 1; millis() < final_time; iteration++) { - partial_time = millis() + 10; - for (int i = 0; i < 4; i++) servo[i].SetPosition(servo_position[i] + (iteration * increment[i])); - while (millis() < partial_time); //pause - } - } - else{ - for (int i = 0; i < 4; i++) servo[i].SetPosition(servo_target[i]); - } - for (int i = 0; i < 4; i++) servo_position[i] = servo_target[i]; -} - -void Zowi::oscillateServos(int A[4], int O[4], int T, double phase_diff[4], float cycle=1){ - for (int i=0; i<4; i++) { - servo[i].SetO(O[i]); - servo[i].SetA(A[i]); - servo[i].SetT(T); - servo[i].SetPh(phase_diff[i]); - } - double ref=millis(); - for (double x=ref; x= 1) for(int i=0;i= 1) for(int i=0;i= 1) for(int i=0;i= 1) for(int i=0;i -#include -#include - - - -class Zowi -{ - public: - void init(int YL, int YR, int RL, int RR, bool load_calibration=0); - void setTrims(int YL, int YR, int RL, int RR); - void saveTrimsOnEEPROM(); - - void moveServos(int time, int servo_target[]); - void oscillateServos(int A[4], int O[4], int T, double phase_diff[4], float cycle); - - void walk(float steps=4, int T=1566); - void turnLeft(float steps, int T); - void turnRight(float steps, int T); - void backward(float steps, int T); - void jump(float steps=1, int T=1000); - - - private: - - Oscillator servo[4]; - int servo_trim[4]; - int servo_position[4]; - - unsigned long final_time; - unsigned long partial_time; - float increment[4]; -}; - -#endif - -