-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ActivityBot 360 IR distance test and IR following examples
Add examples to ActivityBoe360 folder for IR distance detection and following.
- Loading branch information
1 parent
16a3d78
commit b5a0b0c
Showing
5 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
Learn/Examples/Robots/ActivityBot360/IR Follow the Leader.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
IR Follow the Leader.c | ||
Follow another ActivityBot 360, your hand and other targets. | ||
http://learn.parallax.com/activitybot/ir-follow-the-leader | ||
*/ | ||
|
||
#include "simpletools.h" // Include simpletools | ||
#include "abdrive360.h" | ||
|
||
int irLeft, irRight; // Global variables | ||
int errorLeft, errorRight; | ||
int driveLeft, driveRight; | ||
int setPoint = 4; | ||
int kp = -12; | ||
|
||
int main() // Main function | ||
{ | ||
pwm_start(255); | ||
|
||
low(26); // D/A0 & D/A1 to 0 V | ||
low(27); | ||
|
||
while(1) // Main loop | ||
{ | ||
irLeft = 0; // Detect variables to 0 | ||
irRight = 0; | ||
|
||
for(int da = 189; da >= 0; da -= 27) // Sweep da pins | ||
{ | ||
pwm_set(26, 0, da); | ||
pwm_set(27, 1, da); | ||
freqout(11, 1, 38000); // Left IR LED light | ||
irLeft += input(10); // Check left IR detector | ||
freqout(1, 1, 38000); // Repeat for right detector | ||
irRight += input(2); | ||
} | ||
|
||
errorLeft = setPoint - irLeft; | ||
errorRight = setPoint - irRight; | ||
|
||
driveLeft = kp * errorLeft; | ||
driveRight = kp * errorRight; | ||
|
||
drive_speed(driveLeft, driveRight); | ||
} | ||
} | ||
|
9 changes: 9 additions & 0 deletions
9
Learn/Examples/Robots/ActivityBot360/IR Follow the Leader.side
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
IR Follow the Leader.c | ||
>compiler=C | ||
>memtype=cmm main ram compact | ||
>optimize=-Os | ||
>-m32bit-doubles | ||
>-fno-exceptions | ||
>defs::-std=c99 | ||
>-lm | ||
>BOARD::ACTIVITYBOARD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
IR Test Distances.c | ||
Test distance detection with infrared detectors. | ||
http://learn.parallax.com/activitybot/ir-test-distances | ||
*/ | ||
|
||
#include "simpletools.h" // Include simpletools | ||
#include "abdrive360.h" | ||
|
||
int irLeft, irRight; // Global variables | ||
|
||
int main() // Main function | ||
{ | ||
pwm_start(255); | ||
|
||
low(26); // D/A0 & D/A1 to 0 V | ||
low(27); | ||
|
||
while(1) // Main loop | ||
{ | ||
irLeft = 0; // Detect variables to 0 | ||
irRight = 0; | ||
|
||
for(int da = 189; da >= 0; da -= 27) // Sweep da pins | ||
{ | ||
pwm_set(26, 0, da); | ||
pwm_set(27, 1, da); | ||
freqout(11, 1, 38000); // Left IR LED light | ||
irLeft += input(10); // Check left IR detector | ||
freqout(1, 1, 38000); // Repeat for right detector | ||
irRight += input(2); | ||
} | ||
|
||
print("%c irLeft = %d, irRight = %d ", // Display detector states | ||
HOME, irLeft, irRight); | ||
pause(100); // Pause before repeating | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Test IR Distances.c | ||
>compiler=C | ||
>memtype=cmm main ram compact | ||
>optimize=-Os | ||
>-m32bit-doubles | ||
>-fno-exceptions | ||
>defs::-std=c99 | ||
>-lm | ||
>BOARD::ACTIVITYBOARD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v1.4.118 | ||
v1.4.119 |