Skip to content

Commit

Permalink
New example
Browse files Browse the repository at this point in the history
  • Loading branch information
alkaza committed Nov 27, 2017
1 parent 6e8eb19 commit 83f1e3d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Ctrl-C
- Synchronizing motors
- Obstacle avoidance

**Example files** : `sensor.c motor.c synch.c avoid.c`
**Example files** : `sensor.c motor.c motor_synch.c avoid.c avoid_alter.c`

## Working Principles
### DC Motor Driver
Expand Down
2 changes: 1 addition & 1 deletion src/examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CFLAGS = -I. -Wall
LDFLAGS = -L.
LDLIBS = -lrobot
LIBS = -lwiringPi
EXE = sensor motor synch avoid
EXE = sensor motor motor_synch avoid avoid_alter

all : $(EXE)

Expand Down
41 changes: 41 additions & 0 deletions src/examples/avoid_alter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <stdio.h>
#include <wiringPi.h>
#include "robot.h"

/* Macros */
#define MINDIST 10 // possible range 2~400 cm (3.3V)
#define SPEEDA 150 // possible range 60~255 PWM
#define SPEEDB 150

int turning = 0;
char turn_dir;

int main(void)
{
setup();
float dist;
while (1) {
dist = calc_dist();
delay(10);

/* Modify here */
if ((dist < MINDIST) && (dist > 0)) {
if(prev_dir == FW){
if (turning) {
turning = 0;
turn_dir = LEFT;
}
else {
turning = 1;
turn_dir = RIGHT;
}
}
move_slow(turn_dir, SPEEDA, SPEEDB);
}
else {
move_slow(FW, SPEEDA, SPEEDB);
}
}

return 0;
}
File renamed without changes.

0 comments on commit 83f1e3d

Please sign in to comment.