Skip to content

Commit

Permalink
Timing is Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
savnik committed May 8, 2014
1 parent dd2aa83 commit cee95de
Show file tree
Hide file tree
Showing 5 changed files with 474 additions and 9 deletions.
16 changes: 11 additions & 5 deletions driver.asv
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
clear
STEP_RES = 16;
STEPS_PR_ROUND = 200*STEP_RES;
RADIUS = 0.02; %[m]
RADIUS = 0.0272; %[m]
DIST_PR_STEP = (2*RADIUS*pi)/STEPS_PR_ROUND;

distance = 0;
distance_to_go = 1;
distance_to_go = 2;
steps_to_go = distance_to_go/DIST_PR_STEP
steps = 0;

max_dist = (2^32)-1*DIST_PR_STEP
min_dist = DIST_PR_STEP

%% Omvendt beregning
steps_to_go = 25464
distance_to_go = 1.27
steps_to_go = 20051
distance_to_go = 1.07
DIST_PR_STEP = distance_to_go/steps_to_go
RADIUS = (1/2)*(DIST_PR_STEP*STEPS_PR_ROUND)/pi

Expand All @@ -26,11 +29,14 @@ RADIUS = (1/2)*(DIST_PR_STEP*STEPS_PR_ROUND)/pi

%% Tidsberegning

time_to_go = 2*60*60 %% [s] The time to do the dist
time_to_go = 600 %% [s] The time to do the dist
steps_to_go = distance_to_go/DIST_PR_STEP
time_pr_step = time_to_go/steps_to_go
time_pr_step_ms = time_pr_step*10^3


total_time=(time_pr_step*steps_to_go)-(0.003*steps_to_go)

%%
m = 10
s = m*60
Expand Down
12 changes: 9 additions & 3 deletions driver.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
clear
STEP_RES = 16;
STEPS_PR_ROUND = 200*STEP_RES;
RADIUS = 0.02; %[m]
RADIUS = 0.0272; %[m]
DIST_PR_STEP = (2*RADIUS*pi)/STEPS_PR_ROUND;

distance = 0;
distance_to_go = 1;
distance_to_go = 2;
steps_to_go = distance_to_go/DIST_PR_STEP
steps = 0;

max_dist = (2^32)-1*DIST_PR_STEP
min_dist = DIST_PR_STEP

%% Omvendt beregning
steps_to_go = 20051
distance_to_go = 1.07
Expand All @@ -26,11 +29,14 @@

%% Tidsberegning

time_to_go = 2*60*60 %% [s] The time to do the dist
time_to_go = 600 %% [s] The time to do the dist
steps_to_go = distance_to_go/DIST_PR_STEP
time_pr_step = time_to_go/steps_to_go
time_pr_step_ms = time_pr_step*10^3


total_time=(time_pr_step*steps_to_go)-(0.003*steps_to_go)

%%
m = 10
s = m*60
Expand Down
3 changes: 2 additions & 1 deletion driver_2_0/driver_2_0/driver_2_0.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Timelapse Dolly - Automation, Systemer og Komponenter
@version 2.0
@version 2.1
@date 2014-05-05
@author Peter Savnik
Expand Down Expand Up @@ -189,6 +189,7 @@ void establishContact() {

/*
|| @changelog
|| | 2.1 2014-05-08 - Peter Savnik : Dist is calibrated
|| | 2.0 2014-05-06 - Peter Savnik : Added state machine & Millis as delay
|| | 1.3 2014-05-05 - Peter Savnik : Added Potentiometer control of time
|| | 1.2 2014-05-01 - Peter Savnik : Added Debug function, enable serial output when debugging
Expand Down
201 changes: 201 additions & 0 deletions driver_2_0/driver_2_1/driver_2_1.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/*
Timelapse Dolly - Automation, Systemer og Komponenter
@version 2.1
@date 2014-05-05
@author Peter Savnik
@Description
Make a step motor control motion of a Camera mounted on a dolly.
Input: Distance and Time
*/
#include <math.h>
#include <Keypad.h>

const int DEBUG = 0; // Toogle Serial output
const int PIN_RUN = 8;
const int PIN_STEP = 9;
const int PIN_ENABLE = A0;
const int PIN_TIME_SCALE_POT = A1;
const float Pi = 3.14159;

const float STEP_RES = 16.0; // Stepper resolution
const float STEPS_PR_ROUND = 200.0*STEP_RES; // Total steps pr. round
const float RADIUS = 0.0272; // [m]
const float DIST_PR_STEP = (2.0*RADIUS*Pi)/STEPS_PR_ROUND; //[cm] Omkreds/steps pr round


float distance = 0.0; // [m] Record the number of steps we've taken
float distance_to_go = 1.0; // [m]
long steps_to_go = (distance_to_go)/DIST_PR_STEP; // total amount of steps to the distance_to_go
float time_to_go = 60; // [s] time to do the distance
int steps = 0; // Total count of steps
int run = 0; // Control var for start/stop fcn
int dir = 1; // Control direction
int sensorValue = 0; // Time scale pot sensor
int stepState = 0; // Step output state

String state = "IDLE", next_state = "IDLE"; // Statemachine control

float time_pr_step;
float time_pr_step_ms;

unsigned long current_time = 0;
unsigned long prev_time = 0;

void setup() {
Serial.begin(9600);
while(!Serial){
; // wait for serial to begin
}
Serial.println('Timelapse Dolly Start');


pinMode(PIN_RUN, INPUT_PULLUP);
pinMode(PIN_STEP, OUTPUT);
pinMode(PIN_ENABLE, OUTPUT);
pinMode(PIN_TIME_SCALE_POT, INPUT);
digitalWrite(PIN_STEP, LOW);
digitalWrite(PIN_ENABLE, HIGH);

//establishContact(); // send a byte to establish contact until receiver responds
}

void loop() {

run = digitalRead(PIN_RUN);

// Statemachine!
if (state == "IDLE"){
// Wait for action

// Calc delay time
float time_pr_step = time_to_go/steps_to_go; // the delay time between steps
float time_pr_step_ms = time_pr_step*pow(10,3); // Convert to millisec
if (time_pr_step_ms < 1) time_pr_step_ms = 1; // Don't go too fast!

// Print Parameters
Serial.print("Dist: ");
Serial.print(distance_to_go);
Serial.print(", Steps to go:");
Serial.print(steps_to_go);
Serial.print(", Time: ");
Serial.print(time_to_go);
Serial.print(", Step Time: ");
Serial.println(time_pr_step_ms);

// Change state
// Start running
if(run == LOW){
Serial.println("Next state: MOVE!");
digitalWrite(PIN_ENABLE, LOW);
next_state = "MOVE";
}
else{
next_state = "IDLE";
}

}
else if (state == "MOVE"){
// MOVE
// Check to see if we are at the end of our move
time_pr_step = 1;
if ((steps*DIST_PR_STEP < distance_to_go) && (run == LOW)) {
current_time = millis();
if(current_time-prev_time >= time_pr_step/2){
// Step toogle
if(stepState == 0){
digitalWrite(PIN_STEP, HIGH); // step high
stepState = 1;
}
else if(stepState == 1){
digitalWrite(PIN_STEP, LOW); // step low
stepState = 0;
steps = 1+steps; // Incremetent steps
Serial.println(steps_to_go-steps);
}
prev_time = current_time;
}

}

// Change state
if(run == HIGH){ // Stop running
next_state = "IDLE";
digitalWrite(PIN_ENABLE, HIGH);
}
else{
next_state = "MOVE"; // Stay in state
}

}
else {
Serial.print("Error in statemachine: ");
Serial.println(state);
}
if(state != next_state) Serial.println(next_state);
state = next_state;





/*
// If dist is done disable
if ((steps*DIST_PR_STEP >= distance_to_go)){
disableMotor();
steps = 0;
}
*/
}


void enableMotor(){
// Enable motor driver
digitalWrite(PIN_ENABLE, LOW);
if(DEBUG == 1) Serial.println("Start");
}

void disableMotor(){
// Enable motor driver
digitalWrite(PIN_ENABLE, HIGH);
if(DEBUG == 1) Serial.println("Stop");
}


void enableMotorToogle(){
// Enable motor driver
if(run == 0){
enableMotor();
run = 1;
}
else if(run == 1){
disableMotor();
run = 0;
}
}




void establishContact() {
while (Serial.available() <= 0) {
Serial.println("0,0,0"); // send an initial string
delay(300);
}
}

/*
|| @changelog
|| | 2.1 2014-05-08 - Peter Savnik : Dist is calibrated
|| | 2.0 2014-05-06 - Peter Savnik : Added state machine & Millis as delay
|| | 1.3 2014-05-05 - Peter Savnik : Added Potentiometer control of time
|| | 1.2 2014-05-01 - Peter Savnik : Added Debug function, enable serial output when debugging
|| | 1.1 2014-05-01 - Peter Savnik : Added direction control
|| | 1.0 2014-05-01 - Peter Savnik : Initial Release
|| #
*/


Loading

0 comments on commit cee95de

Please sign in to comment.