PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Examples
Robots
ActivityBot
Roaming with Whiskers.c
1
/*
2
Roaming with Whiskers.c
3
4
Go forward until object detected by whisker(s). Then, back up, turn
5
and go a new direction.
6
7
http://learn.parallax.com/activitybot/roaming-whiskers
8
*/
9
10
#include "
simpletools.h
"
// Include simpletools library
11
#include "
abdrive.h
"
// Include abdrive library
12
13
int
main
()
// main function
14
{
15
freqout
(4, 2000, 3000);
// Speaker tone: 2 s, 3 kHz
16
17
while
(1)
// Main loop
18
{
19
// Go forward for 1/50th of a second.
20
drive_speed
(64, 64);
// Go forward
21
22
// Check whisker states.
23
int
wL =
input
(7);
// Left whisker -> wL variable
24
int
wR =
input
(8);
// Right whisker -> wR variable
25
26
// If whisker(s) pressed, avoid obstacle.
27
if
(wR == 0)
// Just right whisker
28
{
29
drive_speed
(-64, -64);
// Back up 1 second
30
pause
(1000);
31
drive_speed
(-64, 64);
// Turn left 0.5 seconds
32
pause
(500);
33
}
34
else
if
(wL == 0)
// Just left whisker
35
{
36
drive_speed
(-64, -64);
// Back up 1.0 second
37
pause
(1000);
38
drive_speed
(64, -64);
// Turn right 0.5 seconds
39
pause
(500);
40
}
41
}
42
}
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
freqout
void freqout(int pin, int msTime, int frequency)
Use same cog to send square wave of a certain frequency for a certain amount of time....
Definition:
freqout.c:10
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,...
main
int main(void)
Definition:
GraphicsTest.c:20
input
int input(int pin)
Set an I/O pin to input and return 1 if pin detects a high signal, or 0 if it detects low.
Definition:
input.c:19
abdrive.h
This library takes care of encoder monitoring and servo signaling, and provides a simple set of funct...
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17