forked from Rhoban/Metabot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmotors.cpp
More file actions
80 lines (73 loc) · 1.43 KB
/
motors.cpp
File metadata and controls
80 lines (73 loc) · 1.43 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
#ifndef __EMSCRIPTEN__
#include <commands.h>
#include <dxl.h>
#endif
#include "leds.h"
#include "motion.h"
#include "mapping.h"
#include "motors.h"
static float motors_positions[12];
static bool is_enabled = false;
void motors_colorize()
{
if (motors_enabled()) {
// Colorizing the front of the robot
colorize();
} else {
// Turning all leds red
led_set_all(LED_R);
}
}
void motors_enable()
{
// Motors are enabled
is_enabled = true;
#ifndef __EMSCRIPTEN__
// Running the actual motors
start();
#endif
motors_colorize();
}
void motors_disable()
{
// Motors are disabled
is_enabled = false;
// Marking leds as non custom
#ifndef __EMSCRIPTEN__
// Stopping the actual motors
stop();
#endif
motors_colorize();
}
bool motors_enabled()
{
#ifndef __EMSCRIPTEN__
return started;
#else
return is_enabled;
#endif
}
void motors_read()
{
#ifndef __EMSCRIPTEN__
ui8 ids[12] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
uint16_t positions[24];
if (dxl_sync_read(ids, 12, DXL_POSITION, 2, (ui8*)positions)) {
for (int k=0; k<12; k++) {
motors_positions[k] = dxl_value_to_position(k+1, positions[k]);
}
}
#endif
}
float motors_get_position(int i)
{
#ifndef __EMSCRIPTEN__
if (motors_enabled()) {
return motion_get_motor(i);
} else {
return motors_positions[i];
}
#else
return motion_get_motor(i);
#endif
}