-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasserv_uc.ino
92 lines (69 loc) · 1.68 KB
/
asserv_uc.ino
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
#include <Encoder.h>
#include <Servo.h>
#include <Ping.h>
#include "config.h"
#include "utils.h"
#include "odometry.h"
#include "asserv.h"
#include "hbridge.h"
#include "navigation.h"
#include "i2c.h"
#include "api.h"
Encoder coderLeft(CODER_L_A,CODER_L_B);
Encoder coderRight(CODER_R_A,CODER_R_B);
HBridge motorLeft(MOTOR_L_PWM,MOTOR_L_DIR,MOTOR_L_BRAKE);
HBridge motorRight(MOTOR_R_PWM,MOTOR_R_DIR,MOTOR_R_BRAKE);
Servo servoBrasLeft;
Servo servoBrasRight;
//Ping ping = Ping(ULTRASOUND_PIN);
IntervalTimer timer;
static void refreshStatus();
void setup()
{
pinMode(DEBUG_PIN_GENERAL,OUTPUT);
servoBrasLeft.attach(SERVO_BRAS_LEFT);
servoBrasRight.attach(SERVO_BRAS_RIGHT);
servoBrasLeft.write(SERVO_BRAS_LEFT_IDLE);
servoBrasRight.write(SERVO_BRAS_RIGHT_IDLE);
//Ping ping = Ping(ULTRASOUND_PIN);
Serial.begin(115200);
i2c_init();
timer.begin(refreshStatus, 1000000/REFRESH_FREQ);
motorRight.setup();
motorLeft.setup();
asserv_setCoeffDist(1*9000,0);
asserv_setCoeffAngle(1*10000,0);
asserv_setSpeedMaxDist(200000);
asserv_setSpeedMaxAngle(200000);
asserv_setTarget(0,0,ABS);
odo_enable();
asserv_enable();
}
void loop()
{
serial_process();
if(cmd_callback) {
// delay(10);
// Serial.println("############################"); //dont remove
int cb = cmd_callback();
if (cb) {
cmd_callback=NULL;
}
}
// DUMP_VAR(odo_angle);
DUMP_VAR(coderLeft.read());
DUMP_VAR(coderRight.read());
// DUMP_VAR(motorRight.getSpeed());
// DUMP_VAR(motorLeft.getSpeed());
//nav_gotoPoint(0.4,0.4,0.03);
// motorLeft.setSpeed(100);
// motorRight.setSpeed(200);
//delay(300);
}
static void refreshStatus()
{
DEBUG_PIN_ON;
odo_update();
asserv_run();
DEBUG_PIN_OFF;
}