PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Examples
Robots
Arlo
Arlo - Test Encoder Connections.c
1
/*
2
Arlo - Test Encoder Connections.c
3
4
This program tests to make sure the Arlo's wheel encoder connections
5
are correct. The Arlo will not be ready for the next step until you
6
have verified that the number of encoder transitions (ticks) for both
7
wheels are positive when the wheels roll forward.
8
9
If you have not already completed Test Arlo Motor Connections.c,
10
complete it first, then continue from here.
11
12
Use SimpleIDE's Run with Terminal button to run this program. If the
13
SimpleIDE Terminal displays the "Encoder connections are correct!..."
14
message, your Arlo is ready for the next step, which is running
15
navigation programs.
16
17
If the SimpleIDE Terminal instead displays one or more "ERROR..."
18
messages, those encoder encoder connections will need to be
19
corrected. For example, if the messages says, "ERROR: Motor 1
20
encoder connections are reversed!", you will need to unplug and
21
swap the two 3-wire encoder cables next to the Motor 1 terminal
22
on the DHB-10, swap them, and plug them back in.
23
24
Make sure to test between each adjustment. Your arlo will not be
25
ready for the next step until you get the success message from
26
this test.
27
*/
28
29
#include "
simpletools.h
"
// Include simpletools library
30
#include "arlodrive.h"
// Include arlodrive library
31
32
int
ticksL, ticksR;
// Encoder tick counts
33
34
int
main
()
// Main function
35
{
36
print
(
"Testing...\n\n"
);
// Display status
37
38
drive_feedback
(0);
// Disable encoder feedback
39
drive_clearTicks();
// Clear encoder values
40
41
drive_speed
(32, 32);
// Drive motors at 1/4 power
42
pause
(4000);
// ...for 4 seconds
43
drive_speed
(0, 0);
// Cut power to motors
44
45
drive_getTicks
(&ticksL, &ticksR);
// Get encoder measurements
46
47
print
(
"ticksL = %d, ticksR = %d\n\n"
,
// Display encoder measurements
48
ticksL, ticksR);
49
50
if
((ticksL > 175) && (ticksL < 325) &&
// Both distances positive?
51
(ticksR > 175) && (ticksR < 325))
52
{
53
print
(
"Encoder connections are \n"
);
// Success message
54
print
(
"correct! Your Arlo is \n"
);
55
print
(
"ready for the next step.\n\n"
);
56
}
57
else
58
{
59
if
(ticksL > 175 && ticksL < 325)
// Left encoders cables correct?
60
{
61
print
(
"Motor 1 encoder cables \n"
);
// Correct encoder message
62
print
(
"are connected correctly.\n\n"
);
63
}
64
else
if
(ticksL > -325 && ticksL < -125)
// Left encoders cables swapped?
65
{
66
print
(
"ERROR: Motor 1 encoder \n"
);
// Swapped encoder message
67
print
(
"connections are reversed!\n\n"
);
68
}
69
else
// Other problem
70
{
71
print
(
"ERROR: Motor 1 encoder \n"
);
// Other encoder error message
72
print
(
"values out of range. \n"
);
73
print
(
"Recheck encoder connections\n"
);
74
print
(
" and assemblies.\n\n"
);
75
}
76
if
(ticksR > 175 && ticksR < 325)
// Right encoders cables correct?
77
{
78
print
(
"Motor 2 encoder cables\n"
);
// Correct encoder message
79
print
(
"are connected correctly.\n\n"
);
80
}
81
else
if
(ticksR > -325 && ticksR < -125)
// Right encoders cables swapped?
82
{
83
print
(
"ERROR: Motor 2 encoder\n"
);
// Swapped encoder message
84
print
(
"connections are reversed!\n\n"
);
85
}
86
else
// Other problem
87
{
88
print
(
"ERROR: Motor 2 encoder\n"
);
// Other encoder error message
89
print
(
"values out of range.\n"
);
90
print
(
"Recheck encoder connections\n"
);
91
print
(
"and assemblies.\n\n"
);
92
}
93
}
94
95
print
(
"Test done.\n\n"
);
// Display status
96
}
drive_feedback
void drive_feedback(int enabled)
Enables or disables encoder feedback for speed control.
Definition:
feedback.c:5
drive_getTicks
void drive_getTicks(int *left, int *right)
Get the measured number of ticks the have traveled.
Definition:
getticks.c:9
drive_speed
void drive_speed(int left, int right)
Set wheel speeds in encoder ticks per second. An encoder tick is 1/64th of a revolution,...
Definition:
speed.c:138
pause
void pause(int time)
Delay cog from moving on to the next statement for a certain length of time.
Definition:
libws2812.c:125
simpletools.h
This library provides convenient functions for a variety of microcontroller I/O, timing,...
print
int print(const char *format,...) __attribute__((format(printf
Print format "..." args to the default simple terminal device. The output is limited to 256 bytes.
main
int main(void)
Definition:
GraphicsTest.c:20
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17