Skip to content

Commit

Permalink
ActivityBot 360 IR distance test and IR following examples
Browse files Browse the repository at this point in the history
Add examples to ActivityBoe360 folder for IR distance detection and following.
  • Loading branch information
AndyLindsay committed Nov 5, 2018
1 parent 16a3d78 commit b5a0b0c
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 1 deletion.
49 changes: 49 additions & 0 deletions Learn/Examples/Robots/ActivityBot360/IR Follow the Leader.c
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);
}
}

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
41 changes: 41 additions & 0 deletions Learn/Examples/Robots/ActivityBot360/Test IR Distances.c
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
}
}

9 changes: 9 additions & 0 deletions Learn/Examples/Robots/ActivityBot360/Test IR Distances.side
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
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.4.118
v1.4.119

0 comments on commit b5a0b0c

Please sign in to comment.