forked from hackstub/atelierArduino
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeRobot.ino
More file actions
91 lines (71 loc) · 1.75 KB
/
codeRobot.ino
File metadata and controls
91 lines (71 loc) · 1.75 KB
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
//
// Hackteliers Fevrier 2014
// Code pour controller le robot
//
#include <Servo.h>
// #########################
// # Gestion des moteurs #
// #########################
#define pinServoRoueGauche 9
#define pinServoRoueDroite 10
#define centerGauche 90
#define centerDroite 90
Servo servoRoueGauche; // create servo object to control a servo
Servo servoRoueDroite; // create servo object to control a servo
void initServos()
{
servoRoueGauche.attach(pinServoRoueGauche);
servoRoueDroite.attach(pinServoRoueDroite);
}
void stopServos()
{
servoRoueGauche.write(centerGauche);
servoRoueDroite.write(centerDroite);
servoRoueGauche.detach();
servoRoueDroite.detach();
}
// ######################
// # Fonction avancer #
// ######################
void avancer(int vitesse, int duree)
{
initServos();
servoRoueGauche.write(centerGauche+vitesse);
servoRoueDroite.write(centerDroite-vitesse);
delay(duree);
stopServos();
}
// ######################
// # Fonction tourner #
// ######################
#define rotationEtalon 7150 // time to do 360°
void tourner(float fraction)
{
int vitesse = 2.5 * fraction / abs(fraction);
int duree = (int) (rotationEtalon * abs(fraction));
initServos();
servoRoueGauche.write(centerGauche+vitesse);
servoRoueDroite.write(centerDroite+vitesse);
delay(duree);
stopServos();
}
// #########################
// # Pour la calibration #
// #########################
void calibrationRepos() { avancer(0,10000); }
void calibrationRotation() { tourner(4); delay(10000); }
// ##################
// # Le programme #
// ##################
void setup()
{
}
void loop()
{
avancer(5,2000);
delay(1000);
tourner(0.25);
delay(1000);
//calibrationRepos();
//calibrationRotation();
}