forked from DexterInd/GoPiGo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_test_all.c
More file actions
183 lines (155 loc) · 5.82 KB
/
Copy pathbasic_test_all.c
File metadata and controls
183 lines (155 loc) · 5.82 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// ####################################################################################
// This is the basic example to use the GoPiGo.
// http://www.dexterindustries.com/GoPiGo/
// History
// ------------------------------------------------
// Date Comments
// 30 Aug 15 Initial Authoring
// 02 Feb 16 Support Encoders
// ## License
//
// GoPiGo for the Raspberry Pi: an open source robotics platform for the Raspberry Pi.
// Copyright (C) 2017 Dexter Industries
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>.
// ####################################################################################
#include "gopigo.h"
int main(void)
{
// Buffer for data being read/ written on the i2c bus
if(init()==-1)
exit(1);
led_on(1);
while(1)
{
char input[2]; /* Store 2 input characters */
printf("Enter cmd: ");
scanf(" %s", &input);
switch (input[0])
{
case 'w': case 'W':
fwd();
break;
case 'a': case 'A':
left();
break;
case 'd': case 'D':
right();
break;
case 's': case 'S':
bwd();
break;
case 'e': case 'E':
increase_speed();
break;
case 'g': case 'G':
decrease_speed();
break;
case 'z': case 'Z':
exit(0);
break;
case 'x': case 'X':
stop();
break;
case 'i': case 'I':
motor_fwd();
break;
case 'k': case 'K':
motor_bwd();
break;
case 'n': case 'N':
left_rot();
break;
case 'm': case 'M':
right_rot();
break;
case 'l': case 'L':
switch(input[1])
{
case 'o': case 'O':
;
int led_val;
printf("Enter 1 for left led and 0 for right led:\n");
scanf(" %d", &led_val);
led_on(led_val);
break;
case 'f': case 'F':
;
int led_val2;
printf("Enter 1 for left led and 0 for right led:\n");
scanf(" %d", &led_val2);
led_off(led_val2);
break;
default:
printf("invalid led command... (o for ON, f for OFF)\n");
break;
}
break;
case 'r': case 'R':
;
int servo_val;
printf("Enter servo position:\n");
scanf(" %d", &servo_val);
servo(servo_val);
break;
case 'v': case 'V':
printf("Firmware Version: %d\n",fw_ver());
break;
case 'u': case 'U':
printf("Ultrasonic Dist: %d\n",us_dist(15));
break;
case 't': case 'T':
switch(input[1])
{
case 'r': case 'R':
;
int val = trim_read();
if(val == -3){
printf("-3, Trim Value Not set\n");
}
else{
printf("%d\n", val-100);
}
break;
case 'w': case 'W':
;
int val2;
printf("Enter trim value to write to EEPROM(-100 to 100):\n");
scanf(" %d", &val2);
trim_write(val2);
pi_sleep(100);
printf("Value in EEPROM: %d\n", trim_read()-100);
break;
case 't': case 'T':
;
int val3;
printf("Enter trim value to test(-100 to 100):\n");
scanf(" %d", &val3);
trim_test(val3);
pi_sleep(100);
printf("Value in EEPROM: %d\n", trim_read()-100);
break;
default:
printf("invalid trim command...\n");
break;
}
break;
case 'c': case 'C':
printf("Motor 0 (left) travelled %i cm\n", enc_read(0));
printf("Motor 1 (right) travelled %i cm\n", enc_read(1));
break;
default:
printf("invalid command...\n");
break;
}
}
return 0;
}