Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial commit

  • Loading branch information...
commit 893b6f77fed6b14cff0ae121457098db1db0ec89 0 parents
@robrighter authored
33 Makefile
@@ -0,0 +1,33 @@
+DEVICE = atmega328p
+MCU = atmega328p
+AVRDUDE_DEVICE = m328p
+DEVICE ?= atmega168
+MCU ?= atmega168
+AVRDUDE_DEVICE ?= m168
+
+CFLAGS=-g -Wall -std=c99 -mcall-prologues -mmcu=$(MCU) $(DEVICE_SPECIFIC_CFLAGS) -Os
+CC=avr-gcc
+OBJ2HEX=avr-objcopy
+LDFLAGS=-Wl,-gc-sections -lpololu_$(DEVICE) -Wl,-relax
+
+PORT ?= /dev/tty.usbmodem00036221
+AVRDUDE=avrdude
+
+TARGET=main
+OBJECT_FILES=main.o calibrate-for-line.o
+
+all: $(TARGET).hex
+
+clean:
+ rm -f *.o *.hex *.obj *.hex
+
+%.hex: %.obj
+ $(OBJ2HEX) -R .eeprom -O ihex $< $@
+
+main.o: main.c
+
+%.obj: $(OBJECT_FILES)
+ $(CC) $(CFLAGS) $(OBJECT_FILES) $(LDFLAGS) -o $@
+
+program: $(TARGET).hex
+ $(AVRDUDE) -p $(AVRDUDE_DEVICE) -c avrisp2 -P $(PORT) -U flash:w:$(TARGET).hex
38 calibrate-for-line.c
@@ -0,0 +1,38 @@
+#include <pololu/3pi.h>
+#include <avr/pgmspace.h>
+
+#define CALIBRATE_COUNTER 80
+#define CALIBRATE_DELAY 20
+#define CALIBRATE_MOTOR_SPEED 40
+#define NUMBER_OF_SENSORS 5
+
+void calibrate_for_line(){
+ //rotate far left, then far right, then back to center while taking readings
+ for(int i=0; i<CALIBRATE_COUNTER; i++){
+ if(i < 20 || i >= 60){
+ set_motors(CALIBRATE_MOTOR_SPEED,-CALIBRATE_MOTOR_SPEED);
+ }
+ else{
+ set_motors(-CALIBRATE_MOTOR_SPEED,CALIBRATE_MOTOR_SPEED);
+ }
+ calibrate_line_sensors(IR_EMITTERS_ON);
+ delay_ms(CALIBRATE_DELAY);
+ }
+ //stop motors, we're all done
+ set_motors(0,0);
+}
+
+void read_and_display_sensor_data(){
+ unsigned int values[NUMBER_OF_SENSORS];
+ unsigned int position = read_line(values,IR_EMITTERS_ON);
+ //print the position on the top line and the values on the 2nd line
+ clear();
+ print_long(position);
+ lcd_goto_xy(0,1);
+ const char displayable[10] = {'0','1','2','3','4','5','6','7','8','9'};
+ for(int i=0; i<NUMBER_OF_SENSORS; i++){
+ //translate the reading into a displayable value (0-9)
+ char c = displayable[values[i]/101];
+ print_character(c);
+ }
+}
2  calibrate-for-line.h
@@ -0,0 +1,2 @@
+void calibrate_for_line();
+void read_and_display_sensor_data();
0  gitignore
No changes.
27 main.c
@@ -0,0 +1,27 @@
+//#include <pololu/orangutan.h>
+#include <pololu/3pi.h>
+#include "calibrate-for-line.h"
+
+int main()
+{
+
+ while(1){
+ while(!button_is_pressed(BUTTON_B)){}
+ wait_for_button_release(BUTTON_B);
+
+ pololu_3pi_init(2000);
+ calibrate_for_line();
+ read_and_display_sensor_data();
+ }
+
+ //dont let the program ever reach the end of execution
+ //or the robot may take over the world
+ return 0;
+}
+
+// Local Variables: **
+// mode: C **
+// c-basic-offset: 4 **
+// tab-width: 4 **
+// indent-tabs-mode: t **
+// end: **
Please sign in to comment.
Something went wrong with that request. Please try again.