-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathOtto.h
136 lines (105 loc) · 3.96 KB
/
Otto.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef Otto_h
#define Otto_h
#include <Servo.h>
#include "Oscillator.h"
#include <EEPROM.h>
#include "US.h"
#include "MaxMatrix.h"
#include "BatReader.h"
#include "Otto_mouths.h"
#include "Otto_sounds.h"
#include "Otto_gestures.h"
#include "SoftSerialCommand.h"
#include "OttoSerialCommand.h"
//-- Constants
#define FORWARD 1
#define BACKWARD -1
#define LEFT 1
#define RIGHT -1
#define SMALL 5
#define MEDIUM 15
#define BIG 30
#define HIP_L 2 // connect Servo Hip left to D2
#define FOOT_L 4 // Connect Servo Foot Left to D4
#define HIP_R 3 // Connect Servo Hip right to D3
#define FOOT_R 5 // COnnect Servo Foot Right to D5
#define PIN_Buzzer 13
#define PIN_Trigger 8
#define PIN_Echo 9
#define PIN_NoiseSensor A6
///define Bluetooth in SoftwareSerial
#define BT_Rx 7
#define BT_Tx 6
//define Max7219 pins
#define PIN_DIN 10 //max 7219
#define PIN_CS 11
#define PIN_CLK 12
class Otto
{
public:
//-- Otto initialization
void init(int YL, int YR, int RL, int RR, bool load_calibration=true, int NoiseSensor=PIN_NoiseSensor, int Buzzer=PIN_Buzzer, int USTrigger=PIN_Trigger, int USEcho=PIN_Echo);
//-- Attach & detach functions
void attachServos();
void detachServos();
//-- Oscillator Trims
void setTrims(int YL, int YR, int RL, int RR);
void saveTrimsOnEEPROM();
//-- Predetermined Motion Functions
void _moveServos(int time, int servo_target[]);
void oscillateServos(int A[4], int O[4], int T, double phase_diff[4], float cycle);
//-- HOME = Otto at rest position
void home();
bool getRestState();
void setRestState(bool state);
//-- Predetermined Motion Functions
void jump(float steps=1, int T = 2000);
void walk(float steps=4, int T=1000, int dir = FORWARD);
void turn(float steps=4, int T=2000, int dir = LEFT);
void bend (int steps=1, int T=1400, int dir=LEFT);
void shakeLeg (int steps=1, int T = 2000, int dir=RIGHT);
void updown(float steps=1, int T=1000, int h = 20);
void swing(float steps=1, int T=1000, int h=20);
void tiptoeSwing(float steps=1, int T=900, int h=20);
void jitter(float steps=1, int T=500, int h=20);
void ascendingTurn(float steps=1, int T=900, int h=20);
void moonwalker(float steps=1, int T=900, int h=20, int dir=LEFT);
void crusaito(float steps=1, int T=900, int h=20, int dir=FORWARD);
void flapping(float steps=1, int T=1000, int h=20, int dir=FORWARD);
void move(int moveID,int time, int _moveSize);
//-- Sensors functions
float getDistance(); //US sensor
int getNoise(); //Noise Sensor
//-- Battery
double getBatteryLevel();
double getBatteryVoltage();
//-- Mouth & Animations
void putMouth(unsigned long int mouth, bool predefined = true);
void putAnimationMouth(unsigned long int anim, int index);
void clearMouth();
//-- Sounds
void _tone (float noteFrequency, long noteDuration, int silentDuration);
void _playNote(float noteFrequency, long noteDuration);
void bendTones (float initFrequency, float finalFrequency, float prop, long noteDuration, int silentDuration);
void sing(int songName);
//-- Gestures
void playGesture(int gesture);
private:
MaxMatrix ledmatrix=MaxMatrix(PIN_DIN,PIN_CS,PIN_CLK, 1); // init Max7219 LED Matrix, 1 module
BatReader battery;
Oscillator servo[4];
US us;
int servo_pins[4];
int servo_trim[4];
int servo_position[4];
int pinBuzzer;
int pinNoiseSensor;
unsigned long final_time;
unsigned long partial_time;
float increment[4];
bool isOttoResting;
unsigned long int getMouthShape(int number);
unsigned long int getAnimShape(int anim, int index);
void _execute(int A[4], int O[4], int T, double phase_diff[4], float steps);
};
#endif