-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_drive.h
96 lines (73 loc) · 2.55 KB
/
create_drive.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
/*
ATTENTION PROGRAMMER:
Although this header is still included in the lib, we are using the create lib cut and pasted from opencode, as it is still pretty good and I had trouble imporving upon it in a newer version.
Opencode's createlib is good because it bypasses the communication time between the kovan and the create and does its commands on board the create.
If you are curious as to how it works, look at the code, or try to find one of the many papers written by Jeremy Rand about create commands or talk to one of the members from the 2012 - 2013 years, such as Garret Sickles or Kevin Catrone... I think I spelled Catrone wrong.
You can also contact me (Isaac Yates), but I will not garentee that I can give a good explanation of the code.
*/
#ifndef __CREATE_DRIVE_H__
#define __CREATE_DRIVE_H__
#define DRIVE_TRAIN_DIA_MM 264
//returns charge as a percentage. This allows us to compensate for bad charge in other functions. Not implemented yet.
float create_get_charge()
{
return (float)get_create_battery_charge()/(float)get_create_battery_capacity()*100.0;
}
void create_drive_segment(int speed, int distance_mm)
{
set_create_distance(0);
if(distance_mm > 0)
create_drive_direct(speed, speed);//as of 2015, drive_direct is in millimeters per second
else if(distance_mm < 0)
create_drive_direct(-1*speed, -1*speed);
while(abs(get_create_distance()) < distance_mm) msleep(1);
/*msleep(abs(distance_mm)*1000/speed);//haha abs() is kinda nessecary. Almost a headache.*/
create_stop();
}
//positive speed spins the create clockwise.
void create_spin(int velocity)
{
create_drive_direct(velocity, -1*velocity);
}
//positive angle spins the create clockwise
void create_spin_angle(int speed, int angle)
{
set_create_total_angle(0);
if(angle > 0)
{
create_spin(speed);
}
if(angle < 0)
{
create_spin(-1*speed);
}
int beginTime = systime();
while(abs(get_create_total_angle()) < abs(angle)) msleep(1);
int totTime = systime() - beginTime;
printf("\nms per current angle: %d", totTime);
printf("\ncurrent angle: %d", get_create_total_angle());
create_stop();
}
//waits for the create button sensor to be touched
void create_wait_for_bump(int velocity)
{
while(get_create_lbump(0)!=1 || get_create_rbump(0)!=1)
{
if(get_create_lbump(0)==0 && get_create_rbump(0)==1)
{
create_drive(velocity,0);
msleep(100);
}
if(get_create_lbump(0)==1 && get_create_rbump(0)==0)
{
create_drive(0,velocity);
msleep(100);
}
if(get_create_lbump(0)!=1&& get_create_rbump(0)!=1)
{
create_drive_straight(velocity);
msleep(100);
}
}
}
#endif