daily_automated
This commit is contained in:
BIN
trunk/Arduino/sketch_pro_LineFollower/Arduino_DC_Motors.pdf
Normal file
BIN
trunk/Arduino/sketch_pro_LineFollower/Arduino_DC_Motors.pdf
Normal file
Binary file not shown.
BIN
trunk/Arduino/sketch_pro_LineFollower/DC_Motor.jpg
Normal file
BIN
trunk/Arduino/sketch_pro_LineFollower/DC_Motor.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 117 KiB |
BIN
trunk/Arduino/sketch_pro_LineFollower/Matlab_Line_Follower.pdf
Normal file
BIN
trunk/Arduino/sketch_pro_LineFollower/Matlab_Line_Follower.pdf
Normal file
Binary file not shown.
36
trunk/Arduino/sketch_pro_LineFollower/StepperControl.ino.txt
Normal file
36
trunk/Arduino/sketch_pro_LineFollower/StepperControl.ino.txt
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
Adafruit Arduino - Lesson 16. Stepper
|
||||
*/
|
||||
|
||||
#include <Stepper.h>
|
||||
|
||||
int in1Pin = 12;
|
||||
int in2Pin = 11;
|
||||
int in3Pin = 10;
|
||||
int in4Pin = 9;
|
||||
|
||||
Stepper motor(512, in1Pin, in2Pin, in3Pin, in4Pin);
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(in1Pin, OUTPUT);
|
||||
pinMode(in2Pin, OUTPUT);
|
||||
pinMode(in3Pin, OUTPUT);
|
||||
pinMode(in4Pin, OUTPUT);
|
||||
|
||||
// this line is for Leonardo's, it delays the serial interface
|
||||
// until the terminal window is opened
|
||||
while (!Serial);
|
||||
|
||||
Serial.begin(9600);
|
||||
motor.setSpeed(20);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (Serial.available())
|
||||
{
|
||||
int steps = Serial.parseInt();
|
||||
motor.step(steps);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,93 @@
|
||||
|
||||
#define lights 9
|
||||
int LDR1, LDR2, LDR3; // sensor values
|
||||
// calibration offsets
|
||||
int leftOffset = 0, rightOffset = 0, centre = 0;
|
||||
// pins for motor speed and direction
|
||||
int speed1 = 3, speed2 = 11, direction1 = 12, direction2 = 13;
|
||||
// starting speed and rotation offset
|
||||
int startSpeed = 150, rotate = 30; /* CHANGE START SPEED IF YOUR ROBOT IS TOO SLOW, AND CHANGE THE ROTATE VALUE ACCORDING TO YOUR
|
||||
TURNING ANGLE OF BLACK LINE.*/
|
||||
|
||||
// sensor threshold
|
||||
int threshhold = 5;
|
||||
/*Threshold is the difference in values required between the center sensor and the left or right sensors
|
||||
before the robot decides to make a turn. In my case, a setting of 5 worked well. This means that the left and right
|
||||
sensors would need to detect a value greater than the value read from the center sensor plus the
|
||||
threshold value before action is taken. In other words, if the center sensor is reading a value of 600 and
|
||||
the left sensor is reading 603, then the robot will keep going straight. However, a left sensor value of 612
|
||||
(which is higher than the center value plus threshold) means that the left sensor is detecting the back
|
||||
line, indicating that the robot is too far over to the left. So the motors would adjust to make the robot
|
||||
turn to the right to compensate.
|
||||
The threshold value will vary depending on the contrast between your floor (or whatever surface
|
||||
you use) and the black line. This may need to be adjusted to ensure the robot only turns when it has
|
||||
detected enough of a difference between floor and line to ascertain it had moved too far left or right.*/
|
||||
|
||||
// initial speeds of left and right motors
|
||||
int left = startSpeed, right = startSpeed;
|
||||
// Sensor calibration routine
|
||||
void calibrate() {
|
||||
for (int x=0; x<10; x++) { // run this 10 times to obtain average
|
||||
digitalWrite(lights, HIGH); // lights on
|
||||
delay(100);
|
||||
LDR1 = analogRead(0); // read the 3 sensors
|
||||
LDR2 = analogRead(1);
|
||||
LDR3 = analogRead(2);
|
||||
leftOffset = leftOffset + LDR1; // add value of left sensor to total
|
||||
centre = centre + LDR2; // add value of centre sensor to total
|
||||
rightOffset = rightOffset + LDR3; // add value of right sensor to total
|
||||
delay(100);
|
||||
digitalWrite(lights, LOW); // lights off
|
||||
delay(100);
|
||||
}
|
||||
// obtain average for each sensor
|
||||
leftOffset = leftOffset / 10;
|
||||
rightOffset = rightOffset / 10;
|
||||
centre = centre /10;
|
||||
// calculate offsets for left and right sensors
|
||||
leftOffset = centre - leftOffset;
|
||||
rightOffset = centre - rightOffset;
|
||||
}
|
||||
void setup()
|
||||
{
|
||||
// set the motor pins to outputs
|
||||
pinMode(lights, OUTPUT); // lights
|
||||
pinMode(speed1, OUTPUT);
|
||||
pinMode(speed2, OUTPUT);
|
||||
pinMode(direction1, OUTPUT);
|
||||
pinMode(direction2, OUTPUT);
|
||||
// calibrate the sensors
|
||||
calibrate();
|
||||
delay(3000);
|
||||
digitalWrite(lights, HIGH); // lights on
|
||||
delay(100);
|
||||
// set motor direction to forward
|
||||
digitalWrite(direction1, HIGH);
|
||||
digitalWrite(direction2, HIGH);
|
||||
// set speed of both motors
|
||||
analogWrite(speed1,left);
|
||||
analogWrite(speed2,right);
|
||||
}
|
||||
void loop() {
|
||||
// make both motors same speed
|
||||
left = startSpeed;
|
||||
right = startSpeed;
|
||||
// read the sensors and add the offsets
|
||||
LDR1 = analogRead(0) + leftOffset;
|
||||
LDR2 = analogRead(1);
|
||||
LDR3 = analogRead(2) + rightOffset;
|
||||
// if LDR1 is greater than the centre sensor + threshold turn right
|
||||
if (LDR1 > (LDR2+threshhold)) {
|
||||
left = startSpeed + rotate;
|
||||
right = startSpeed - rotate;
|
||||
}
|
||||
// if LDR3 is greater than the centre sensor + threshold turn left
|
||||
if (LDR3 > (LDR2+threshhold)) {
|
||||
left = startSpeed - rotate;
|
||||
right = startSpeed + rotate;
|
||||
}
|
||||
// send the speed values to the motors
|
||||
analogWrite(speed1,left);
|
||||
analogWrite(speed2,right);
|
||||
}
|
||||
|
||||
132
trunk/Arduino/sketch_pro_LineFollower/makefile
Normal file
132
trunk/Arduino/sketch_pro_LineFollower/makefile
Normal file
@@ -0,0 +1,132 @@
|
||||
# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
|
||||
#
|
||||
|
||||
#BOARD_TAG = uno
|
||||
BOARD_TAG = pro
|
||||
BOARD_SUB = 8MHzatmega168
|
||||
include ../paths.mk
|
||||
include ../Arduino.mk
|
||||
|
||||
# --- leonardo (or pro micro w/leo bootloader)
|
||||
#BOARD_TAG = leonardo
|
||||
#MONITOR_PORT = /dev/ttyACM0
|
||||
#include /usr/share/arduino/Arduino.mk
|
||||
|
||||
# --- mega2560 ide 1.0
|
||||
#BOARD_TAG = mega2560
|
||||
#ARDUINO_PORT = /dev/ttyACM0
|
||||
#include /usr/share/arduino/Arduino.mk
|
||||
|
||||
# --- mega2560 ide 1.6
|
||||
#BOARD_TAG = mega
|
||||
#BOARD_SUB = atmega2560
|
||||
#MONITOR_PORT = /dev/ttyACM0
|
||||
#ARDUINO_DIR = /where/you/installed/arduino-1.6.5
|
||||
#include /usr/share/arduino/Arduino.mk
|
||||
|
||||
# --- nano ide 1.0
|
||||
#BOARD_TAG = nano328
|
||||
#MONITOR_PORT = /dev/ttyUSB0
|
||||
#include /usr/share/arduino/Arduino.mk
|
||||
|
||||
# --- nano ide 1.6
|
||||
#BOARD_TAG = nano
|
||||
#BOARD_SUB = atmega328
|
||||
#ARDUINO_DIR = /where/you/installed/arduino-1.6.5
|
||||
#include /usr/share/arduino/Arduino.mk
|
||||
|
||||
# --- pro mini
|
||||
#BOARD_TAG = pro5v328
|
||||
#MONITOR_PORT = /dev/ttyUSB0
|
||||
#include /usr/share/arduino/Arduino.mk
|
||||
|
||||
# --- sparkfun pro micro
|
||||
#BOARD_TAG = promicro16
|
||||
#ALTERNATE_CORE = promicro
|
||||
#BOARDS_TXT = $(HOME)/arduino/hardware/promicro/boards.txt
|
||||
#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/promicro/bootloaders
|
||||
#BOOTLOADER_PATH = caterina
|
||||
#BOOTLOADER_FILE = Caterina-promicro16.hex
|
||||
#ISP_PROG = usbasp
|
||||
#AVRDUDE_OPTS = -v
|
||||
#include /usr/share/arduino/Arduino.mk
|
||||
|
||||
# --- chipkit
|
||||
#BOARD_TAG = mega_pic32
|
||||
#MPIDE_DIR = /where/you/installed/mpide-0023-linux64-20130817-test
|
||||
#include /usr/share/arduino/chipKIT.mk
|
||||
|
||||
# --- pinoccio
|
||||
#BOARD_TAG = pinoccio256
|
||||
#ALTERNATE_CORE = pinoccio
|
||||
#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/pinoccio/bootloaders
|
||||
#BOOTLOADER_PATH = STK500RFR2/release_0.51
|
||||
#BOOTLOADER_FILE = boot_pinoccio.hex
|
||||
#CFLAGS_STD = -std=gnu99
|
||||
#CXXFLAGS_STD = -std=gnu++11
|
||||
#include /usr/share/arduino/Arduino.mk
|
||||
|
||||
# --- fio
|
||||
#BOARD_TAG = fio
|
||||
#include /usr/share/arduino/Arduino.mk
|
||||
|
||||
# --- atmega-ng ide 1.6
|
||||
#BOARD_TAG = atmegang
|
||||
#BOARD_SUB = atmega168
|
||||
#MONITOR_PORT = /dev/ttyACM0
|
||||
#ARDUINO_DIR = /where/you/installed/arduino-1.6.5
|
||||
#include /usr/share/arduino/Arduino.mk
|
||||
|
||||
# --- arduino-tiny ide 1.0
|
||||
#ISP_PROG = usbasp
|
||||
#BOARD_TAG = attiny85at8
|
||||
#ALTERNATE_CORE = tiny
|
||||
#ARDUINO_VAR_PATH = $(HOME)/arduino/hardware/tiny/cores/tiny
|
||||
#ARDUINO_CORE_PATH = $(HOME)/arduino/hardware/tiny/cores/tiny
|
||||
#AVRDUDE_OPTS = -v
|
||||
#include /usr/share/arduino/Arduino.mk
|
||||
|
||||
# --- arduino-tiny ide 1.6
|
||||
#ISP_PROG = usbasp
|
||||
#BOARD_TAG = attiny85at8
|
||||
#ALTERNATE_CORE = tiny
|
||||
#ARDUINO_DIR = /where/you/installed/arduino-1.6.5
|
||||
#include /usr/share/arduino/Arduino.mk
|
||||
|
||||
# --- damellis attiny ide 1.0
|
||||
#ISP_PROG = usbasp
|
||||
#BOARD_TAG = attiny85
|
||||
#ALTERNATE_CORE = attiny-master
|
||||
#AVRDUDE_OPTS = -v
|
||||
#include /usr/share/arduino/Arduino.mk
|
||||
|
||||
# --- damellis attiny ide 1.6
|
||||
#ISP_PROG = usbasp
|
||||
#BOARD_TAG = attiny
|
||||
#BOARD_SUB = attiny85
|
||||
#ALTERNATE_CORE = attiny
|
||||
#F_CPU = 16000000L
|
||||
#ARDUINO_DIR = /where/you/installed/arduino-1.6.5
|
||||
#include /usr/share/arduino/Arduino.mk
|
||||
|
||||
# --- teensy3
|
||||
#BOARD_TAG = teensy31
|
||||
#ARDUINO_DIR = /where/you/installed/the/patched/teensy/arduino-1.0.6
|
||||
#include /usr/share/arduino/Teensy.mk
|
||||
|
||||
# --- mighty 1284p
|
||||
#BOARD_TAG = mighty_opt
|
||||
#BOARDS_TXT = $(HOME)/arduino/hardware/mighty-1284p/boards.txt
|
||||
#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/mighty-1284p/bootloaders
|
||||
#BOOTLOADER_PATH = optiboot
|
||||
#BOOTLOADER_FILE = optiboot_atmega1284p.hex
|
||||
#ISP_PROG = usbasp
|
||||
#AVRDUDE_OPTS = -v
|
||||
#include /usr/share/arduino/Arduino.mk
|
||||
|
||||
# --- atmega328p on breadboard
|
||||
#BOARD_TAG = atmega328bb
|
||||
#ISP_PROG = usbasp
|
||||
#AVRDUDE_OPTS = -v
|
||||
#BOARDS_TXT = $(HOME)/arduino/hardware/breadboard/boards.txt
|
||||
#include /usr/share/arduino/Arduino.mk
|
||||
@@ -0,0 +1,67 @@
|
||||
/* **************************************** *
|
||||
* Title *
|
||||
* **************************************** *
|
||||
* (C) 201x-xx-xx Paolo Iocco *
|
||||
* rev. 0.x *
|
||||
* **************************************** *
|
||||
* Circuit diagram
|
||||
* ---------------
|
||||
* +-------+
|
||||
* | ooooo |
|
||||
* D1--TX<----| A |<---------RAW
|
||||
* D0--RX---->| r |<---------GND
|
||||
* RST------->| d |<---------RST
|
||||
* GND------->| u |<---------VCC
|
||||
* D2-------->| i |-----A3---D17
|
||||
* D3----#--->| n |-----A2---D16
|
||||
* D4-------->| o |-----A1---D15
|
||||
* D5<---#----| |-----A0---D14
|
||||
* D6<---#----| m |-----SCK--D13
|
||||
* D7---------| i |-----MISO-D12
|
||||
* D8---------| n |--#--MOSI-D11
|
||||
* D9----#----| i |--#--SS---D10
|
||||
* +-------+
|
||||
*
|
||||
* ***************************************** */
|
||||
|
||||
|
||||
//int motorPin = 3;
|
||||
int pwm1 = 9;
|
||||
int pwm2 = 10;
|
||||
int pwm3 = 6;
|
||||
int pwm4 = 5;
|
||||
int led = 13;
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(pwm1, OUTPUT);
|
||||
pinMode(pwm2, OUTPUT);
|
||||
pinMode(pwm3, OUTPUT);
|
||||
pinMode(pwm4, OUTPUT);
|
||||
pinMode(led, OUTPUT);
|
||||
Serial.begin(9600);
|
||||
while (!Serial);
|
||||
Serial.println("Speed 0 to 255");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (Serial.available())
|
||||
{
|
||||
int speed = Serial.parseInt();
|
||||
if (speed >= 0 && speed <= 255)
|
||||
{
|
||||
Serial.println(speed);
|
||||
analogWrite(pwm1, speed);
|
||||
analogWrite(pwm2, speed);
|
||||
analogWrite(pwm3, speed);
|
||||
analogWrite(pwm4, speed);
|
||||
}
|
||||
}
|
||||
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
|
||||
delay(900); // wait for a second
|
||||
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
|
||||
delay(100);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user