Skip to content

Commit de98975

Browse files
authored
Merge pull request #54 from zfi/BlocklyProp
Renamed and move directories
2 parents cd5053e + f7ebf7c commit de98975

File tree

147 files changed

+6244
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+6244
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
AB Interpreter.c
3+
4+
Fetches text commands from file on SD card, interprets them,
5+
and executes maneuvers. Requires abdrive 0.5.5 from
6+
ActivityBot library 2013-10-31 or later.
7+
8+
http://learn.parallax.com/activitybot/text-file-maneuver-list
9+
*/
10+
11+
#include "simpletools.h" // Library includes
12+
#include "abdrive.h"
13+
14+
FILE *fp; // File pointer for SD
15+
char str[512]; // File buffer
16+
17+
char cmdbuf[10]; // Command buffer
18+
char valbuf[4]; // Text value buffer
19+
int val; // Value
20+
21+
int main() // Main function
22+
{
23+
int DO = 22, CLK = 23; // SD I/O pins
24+
int DI = 24, CS = 25;
25+
sd_mount(DO, CLK, DI, CS); // Mount SD file system
26+
fp = fopen("navset.txt", "r"); // Open navset.txt
27+
28+
fread(str, 1, 512, fp); // navset.txt -> str
29+
int strLength = strlen(str); // Count chars in str
30+
int i = 0; // Declare index variable
31+
32+
drive_speed(0, 0); // Speed starts at 0
33+
34+
while(1) // Loop through commands
35+
{
36+
// Parse command
37+
while(!isalpha(str[i])) i++; // Find 1st command char
38+
sscan(&str[i], "%s", cmdbuf); // Command -> buffer
39+
i += strlen(cmdbuf); // Idx up by command char count
40+
if(!strcmp(cmdbuf, "end")) break; // If command is end, break
41+
42+
// Parse distance argument
43+
while(!isdigit(str[i])) i++; // Find 1st digit after command
44+
sscan(&str[i], "%s", valbuf); // Value -> buffer
45+
i += strlen(valbuf); // Idx up by value char count
46+
val = atoi(valbuf); // Convert string to value
47+
48+
// Execute command
49+
if(strcmp(cmdbuf, "forward") == 0) // If forward
50+
drive_goto(val, val); // ...go forward by val
51+
else if(strcmp(cmdbuf, "backward") == 0) // If backward
52+
drive_goto(-val, -val); // ... go backward by val
53+
else if(strcmp(cmdbuf, "left") == 0) // If left
54+
drive_goto(-val, val); // ...go left by val
55+
else if(strcmp(cmdbuf, "right") == 0) // If right
56+
drive_goto(val, -val); // ... go right by val
57+
}
58+
59+
fclose(fp); // Close SD file
60+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
AB Interpreter.c
2+
>compiler=C
3+
>memtype=cmm main ram compact
4+
>optimize=-Os
5+
>-m32bit-doubles
6+
>-fno-exceptions
7+
>defs::-std=c99
8+
>-lm
9+
>BOARD::ACTIVITYBOARD
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
ActivityBot Display Calibration.c
3+
4+
Display interpolation table values from calibration
5+
6+
http://learn.parallax.com/activitybot/calibrate-your-activitybot
7+
*/
8+
9+
#include "simpletools.h"
10+
#include "abdrive.h"
11+
12+
int main()
13+
{
14+
drive_displayInterpolation();
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ActivitiyBot Display Calibration.c
2+
>compiler=C
3+
>memtype=cmm main ram compact
4+
>optimize=-Os
5+
>-m32bit-doubles
6+
>-fno-exceptions
7+
>defs::-std=c99
8+
>-lm
9+
>BOARD::ACTIVITYBOARD
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
ActivityBot Calibrate.c
3+
4+
Calibrate the ActivityBot's servos and encoders
5+
6+
http://learn.parallax.com/activitybot/calibrate-your-activitybot
7+
*/
8+
9+
#include "simpletools.h"
10+
#include "abcalibrate.h"
11+
12+
int main()
13+
{
14+
cal_servoPins(12, 13);
15+
cal_encoderPins(14, 15);
16+
17+
high(26);
18+
high(27);
19+
cal_activityBot();
20+
low(26);
21+
low(27);
22+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ActivityBot Calibrate.c
2+
>compiler=C
3+
>memtype=cmm main ram compact
4+
>optimize=-Os
5+
>-m32bit-doubles
6+
>-fno-exceptions
7+
>defs::-std=c99
8+
>-lm
9+
>BOARD::ACTIVITYBOARD
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Center Servos.c
3+
4+
This program can be run if ActivityBot Display Calibration shows that one of
5+
the servos has a zero Encoder Ticks/Second that's more than +/- 30 from
6+
the zero in the Servo Drive column.
7+
8+
This program sends a 1500 us pulses to the left and right servos. With the
9+
PWR switch set to 2, adjust the servos to stay still in in response to these
10+
signals by using a Philips screwdriver to turn the potentiometer adjusting
11+
screw under the hole in the case adjacent to the servo’s cable.
12+
13+
IMPORTANT: After both servos have been adjusted, repeat the procedure in
14+
http://learn.parallax.com/activitybot/calibrate-your-activitybot
15+
*/
16+
17+
#include "simpletools.h"
18+
#include "servo.h"
19+
20+
int main()
21+
{
22+
servo_set(13, 1500);
23+
servo_set(12, 1500);
24+
25+
print("Use a screwdriver to adjust ActivityBot's servos\n");
26+
print("to stop with PWR set to 2.\n\n");
27+
print("Then, make sure to follow the procedure on\n");
28+
print("http://learn.parallax.com/activitybot/calibrate-your-activitybot.\n");
29+
}
30+
31+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Center Servos.c
2+
>compiler=C
3+
>memtype=cmm main ram compact
4+
>optimize=-Os
5+
>-m32bit-doubles
6+
>-fno-exceptions
7+
>defs::-std=c99
8+
>-lm
9+
>BOARD::ACTIVITYBOARD
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Detect and Turn from Obstacle.c
3+
4+
Detect obstacles in the ActivityBot's path, and turn a random direction to avoid them.
5+
6+
http://learn.parallax.com/activitybot/roaming-ultrasound
7+
*/
8+
9+
#include "simpletools.h" // Include simpletools header
10+
#include "abdrive.h" // Include abdrive header
11+
#include "ping.h" // Include ping header
12+
13+
int turn; // Navigation variable
14+
15+
int main() // main function
16+
{
17+
drive_setRampStep(10); // 10 ticks/sec / 20 ms
18+
19+
drive_ramp(128, 128); // Forward 2 RPS
20+
21+
// While disatance greater than or equal
22+
// to 20 cm, wait 5 ms & recheck.
23+
while(ping_cm(8) >= 20) pause(5); // Wait until object in range
24+
25+
drive_ramp(0, 0); // Then stop
26+
27+
// Turn in a random direction
28+
turn = rand() % 2; // Random val, odd = 1, even = 0
29+
30+
if(turn == 1) // If turn is odd
31+
drive_speed(64, -64); // rotate right
32+
else // else (if turn is even)
33+
drive_speed(-64, 64); // rotate left
34+
35+
// Keep turning while object is in view
36+
while(ping_cm(8) < 20); // Turn till object leaves view
37+
38+
drive_ramp(0, 0); // Stop & let program end
39+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Detect and Turn from Obstacle.c
2+
>compiler=C
3+
>memtype=cmm main ram compact
4+
>optimize=-Os
5+
>-m32bit-doubles
6+
>-fno-exceptions
7+
>defs::-std=c99
8+
>-lm
9+
>BOARD::ACTIVITYBOARD
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 "abdrive.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+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Follow with Ping.c
2+
>compiler=C
3+
>memtype=cmm main ram compact
4+
>optimize=-Os
5+
>-m32bit-doubles
6+
>-fno-exceptions
7+
>defs::-std=c99
8+
>-lm
9+
>BOARD::ACTIVITYBOARD
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
Forward Stop Face Right.c
3+
4+
http://learn.parallax.com/activitybot/go-certain-distances
5+
*/
6+
7+
#include "simpletools.h"
8+
#include "abdrive.h"
9+
10+
int main()
11+
{
12+
drive_goto(256, 256);
13+
pause(200);
14+
drive_goto(26, -25);
15+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
IR Roaming.c
3+
4+
Use IR LED and IR receiver pairs as object detectors for robot roaming.
5+
6+
http://learn.parallax.com/activitybot/roaming-infrared-flashlights
7+
*/
8+
9+
#include "simpletools.h" // Library includes
10+
#include "abdrive.h"
11+
12+
int irLeft, irRight; // IR variables
13+
14+
int main() // Main function
15+
{
16+
low(26); // D/A0 & D/A1 to 0 V
17+
low(27);
18+
19+
drive_setRampStep(12); // Max step 12 ticks/s every 20 ms
20+
21+
while(1)
22+
{
23+
freqout(11, 1, 38000); // Check left & right objects
24+
irLeft = input(10);
25+
26+
freqout(1, 1, 38000);
27+
irRight = input(2);
28+
29+
if(irRight == 1 && irLeft == 1) // No obstacles?
30+
drive_rampStep(128, 128); // ...full speed ahead
31+
else if(irLeft == 0 && irRight == 0) // Left & right obstacles?
32+
drive_rampStep(-128, -128); // ...full speed reverse
33+
else if(irRight == 0) // Just right obstacle?
34+
drive_rampStep(-128, 128); // ...rotate left
35+
else if(irLeft == 0) // Just left obstacle?
36+
drive_rampStep(128, -128); // ...rotate right
37+
}
38+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
IR Roaming.c
2+
>compiler=C
3+
>memtype=cmm main ram compact
4+
>optimize=-Os
5+
>-m32bit-doubles
6+
>-fno-exceptions
7+
>defs::-std=c99
8+
>-lm
9+
>BOARD::ACTIVITYBOARD
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
forward = 192
2+
left = 64
3+
right = 128
4+
left = 64
5+
backward = 192
6+
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Navigate by Light.c
3+
4+
http://learn.parallax.com/activitybot/roaming-light-sensors
5+
*/
6+
7+
#include "simpletools.h"
8+
#include "abdrive.h"
9+
10+
int lightLeft, lightRight, ndiff;
11+
int speedLeft, speedRight;
12+
13+
int main()
14+
{
15+
while(1)
16+
{
17+
high(9);
18+
pause(1);
19+
lightLeft = rc_time(9, 1);
20+
21+
high(5);
22+
pause(1);
23+
lightRight = rc_time(5, 1);
24+
25+
ndiff = 200 * lightRight / (lightRight + lightLeft) - 100;
26+
27+
speedLeft = 100;
28+
speedRight = 100;
29+
if(ndiff >= 0) speedLeft -= (ndiff * 4);
30+
else speedRight += (ndiff * 4);
31+
32+
drive_speed(speedLeft, speedRight);
33+
}
34+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Navigate by Light.c
2+
>compiler=C
3+
>memtype=cmm main ram compact
4+
>optimize=-Os
5+
>-m32bit-doubles
6+
>-fno-exceptions
7+
>defs::-std=c99
8+
>-lm
9+
>BOARD::ACTIVITYBOARD

0 commit comments

Comments
 (0)