PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Examples
Robots
ActivityBot360
Follow with Ping.c
1
/*
2
Follow with Ping.c
3
4
Maintain a constant distance between ActivityBot and object.
5
6
http://learn.parallax.com/activitybot/follow-objects-ultrasound
7
*/
8
9
#include "
simpletools.h
"
// Include simpletools header
10
#include "
abdrive360.h
"
// Include abdrive header
11
#include "ping.h"
// Include ping header
12
13
int
distance, setPoint, errorVal, kp, speed;
// Navigation variables
14
15
int
main
()
// main function
16
{
17
setPoint = 32;
// Desired cm distance
18
kp = -10;
// Proportional control
19
20
drive_setRampStep
(6);
// 7 ticks/sec / 20 ms
21
22
while
(1)
// main loop
23
{
24
distance =
ping_cm
(8);
// Measure distance
25
errorVal = setPoint - distance;
// Calculate error
26
speed = kp * errorVal;
// Calculate correction speed
27
28
if
(speed > 128) speed = 128;
// Limit top speed
29
if
(speed < -128) speed = -128;
30
31
drive_rampStep
(speed, speed);
// Use result for following
32
}
33
}
34
drive_rampStep
void drive_rampStep(int left, int right)
This function allows your code to ask for a speed repeatedly in a loop, but each time your code asks ...
Definition:
rampStep.c:5
ping_cm
int ping_cm(int pin)
Report Ping))) measurement as a centimeter distance.
Definition:
ping.c:11
simpletools.h
This library provides convenient functions for a variety of microcontroller I/O, timing,...
drive_setRampStep
void drive_setRampStep(int stepsize)
Overrides the default 12 ticks/second per 50th of a second for ramping.
Definition:
setRampStep.c:5
main
int main(void)
Definition:
GraphicsTest.c:20
abdrive360.h
This library provides a simple set of functions for making the ActivityBot 360 go certain distances a...
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17