Commit a6eca077 authored by Josh Conway's avatar Josh Conway

Initial commit

parents
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:lc="http://www.librecad.org" xmlns:xlink="http://www.w3.org/1999/xlink" width="346.28mm" height="133mm" viewBox="0 0 346.28 133">
<g lc:layername="0" lc:is_locked="false" lc:is_construction="false" fill="none" stroke="black" stroke-width="1">
<path d="M7,119 A7,7 0 0,0 7,133 "/>
<line x1="173.14" y1="119" x2="7" y2="119"/>
<line x1="7" y1="133" x2="173.14" y2="133"/>
<circle cx="7" cy="126" r="2.6"/>
<circle cx="173.14" cy="126" r="2.6"/>
<path d="M173.14,133 A7,7 0 0,0 173.14,119 "/>
<path d="M7,102 A7,7 0 0,0 7,116 "/>
<line x1="173.14" y1="102" x2="7" y2="102"/>
<line x1="7" y1="116" x2="173.14" y2="116"/>
<circle cx="7" cy="109" r="2.6"/>
<circle cx="173.14" cy="109" r="2.6"/>
<path d="M173.14,116 A7,7 0 0,0 173.14,102 "/>
<path d="M7,85 A7,7 0 0,0 7,99 "/>
<line x1="173.14" y1="85" x2="7" y2="85"/>
<line x1="7" y1="99" x2="173.14" y2="99"/>
<circle cx="7" cy="92" r="2.6"/>
<circle cx="173.14" cy="92" r="2.6"/>
<path d="M173.14,99 A7,7 0 0,0 173.14,85 "/>
<path d="M7,68 A7,7 0 0,0 7,82 "/>
<line x1="173.14" y1="68" x2="7" y2="68"/>
<line x1="7" y1="82" x2="173.14" y2="82"/>
<circle cx="7" cy="75" r="2.6"/>
<circle cx="173.14" cy="75" r="2.6"/>
<path d="M173.14,82 A7,7 0 0,0 173.14,68 "/>
<path d="M7,51 A7,7 0 0,0 7,65 "/>
<line x1="173.14" y1="51" x2="7" y2="51"/>
<line x1="7" y1="65" x2="173.14" y2="65"/>
<circle cx="7" cy="58" r="2.6"/>
<circle cx="173.14" cy="58" r="2.6"/>
<path d="M7,34 A7,7 0 0,0 7,48 "/>
<line x1="173.14" y1="34" x2="7" y2="34"/>
<line x1="7" y1="48" x2="173.14" y2="48"/>
<circle cx="7" cy="41" r="2.6"/>
<circle cx="173.14" cy="41" r="2.6"/>
<path d="M7,17 A7,7 0 0,0 7,31 "/>
<line x1="173.14" y1="17" x2="7" y2="17"/>
<line x1="7" y1="31" x2="173.14" y2="31"/>
<circle cx="7" cy="24" r="2.6"/>
<circle cx="173.14" cy="24" r="2.6"/>
<path d="M7,0 A7,7 0 0,0 7,14 "/>
<line x1="173.14" y1="0" x2="7" y2="0"/>
<line x1="7" y1="14" x2="173.14" y2="14"/>
<circle cx="7" cy="7" r="2.6"/>
<circle cx="173.14" cy="7" r="2.6"/>
<line x1="339.28" y1="51" x2="173.14" y2="51"/>
<line x1="173.14" y1="65" x2="339.28" y2="65"/>
<line x1="339.28" y1="34" x2="173.14" y2="34"/>
<line x1="173.14" y1="48" x2="339.28" y2="48"/>
<line x1="339.28" y1="17" x2="173.14" y2="17"/>
<line x1="173.14" y1="31" x2="339.28" y2="31"/>
<line x1="339.28" y1="0" x2="173.14" y2="0"/>
<line x1="173.14" y1="14" x2="339.28" y2="14"/>
<circle cx="339.28" cy="58" r="2.6"/>
<circle cx="339.28" cy="41" r="2.6"/>
<circle cx="339.28" cy="24" r="2.6"/>
<circle cx="339.28" cy="7" r="2.6"/>
<path d="M339.28,65 A7,7 0 0,0 339.28,51 "/>
<path d="M339.28,48 A7,7 0 0,0 339.28,34 "/>
<path d="M339.28,31 A7,7 0 0,0 339.28,17 "/>
<path d="M339.28,14 A7,7 0 0,0 339.28,0 "/>
</g>
</svg>
This diff is collapsed.
This diff is collapsed.
#define MIN_WAVELENGTH 153.0 // millimeters
#define MAX_WAVELENGTH 900.0 // millimeters
// Stepper controller details
#define X_STEP_BIT 5 // Nano Digital Pin 5
#define X_DIRECTION_BIT 2 // Nano Digital Pin 2
#define X_LIMIT_BIT 9 // Digital Pin 9
#define X_MICROSTEPPING 1 // No microstepping
// Leadscrew details
#define rotation 1.41111111 // 25.4mm / 18 (threads per inch) in millimeters
#define stepsPerRotation 200
// Serial variables
char incomingByte; // a variable to read incoming serial data into
String incomingFrequency; // Varible to store the command
// Position variables
volatile long int position = -1; // -1 means 'we havent homed'. There's no negative positions in our arrangement here.
void setup() {
Serial.begin(115200);
pinMode(X_STEP_BIT, OUTPUT);
pinMode(X_DIRECTION_BIT, OUTPUT);
pinMode(X_LIMIT_BIT, INPUT_PULLUP); // inverted logic. connected or 1 = not triggered. disconnected or 0 = triggered
homeStepper();
Serial.println("Please enter freq in MHz.");
}
void loop() {
if (Serial.available() > 0) {
incomingByte = Serial.read();
incomingFrequency.concat(String(incomingByte));
}
if ( incomingFrequency.endsWith("\r") || incomingFrequency.endsWith("\n") ) {
Serial.print("wavelength: "); Serial.print(1000*(299792458 / (incomingFrequency.toFloat() * 1000000.0))); Serial.println(" mm");
executeCode(incomingFrequency);
incomingFrequency.remove(0);
}
if ( incomingFrequency.length() > 10 ) {
Serial.println("Length of command exceeded. Please enter freq in MHz.");
incomingFrequency.remove(0);
}
}
void executeCode(String freq) {
float targetWavelength = frequencyToWavelength(freq.toFloat() * 1000000.0); // returns millimeters of frequency
float offset = targetWavelength - (MIN_WAVELENGTH + (position*rotation)/200.0); // returns offset of millimeters, positive or negative
Serial.print("start : "); Serial.println((MIN_WAVELENGTH + (position*rotation)/200.0));
Serial.print("travel : "); Serial.println(offset);
if (offset < 0){ // if negative...
digitalWrite(X_DIRECTION_BIT,LOW); // reverse direction
for (long int i=0; i>millimetersToSteps(offset); --i){ incrementStepper(); position = position - 1; } // and go backwards that many steps
}
if (offset > 0){
digitalWrite(X_DIRECTION_BIT,HIGH);
for (long int i=0; i<millimetersToSteps(offset); ++i){ incrementStepper(); position = position + 1; }
}
}
void incrementStepper() {
if ((digitalRead(X_DIRECTION_BIT) == 0) && (digitalRead(X_LIMIT_BIT) == 1)) {
return; // Failsafe if the direction is 'bad' AND limit switch is triggered
}
//if (MIN_WAVELENGTH + (position / stepsPerRotation)*rotation >= MAX_WAVELENGTH) {
// return; // Failsafe on max end
//}
digitalWrite(X_STEP_BIT, HIGH);
delayMicroseconds(500);
digitalWrite(X_STEP_BIT, LOW);
delayMicroseconds(500);
}
void homeStepper() {
Serial.println("Homing...");
digitalWrite(X_DIRECTION_BIT, LOW); // go in reverse direction
while (digitalRead(X_LIMIT_BIT) == LOW) { // When we dont hit the endstop, move towards endstop
incrementStepper();
}
digitalWrite(X_DIRECTION_BIT, HIGH); // clean up direction flag
position = 0 ; // We're at home, so set position to 0.
Serial.println("Done homing...");
}
// receives hertz, returns in millimeters
float frequencyToWavelength(float frequency){
float wavelength = (299792458.0/frequency)*1000;
return wavelength;
}
// receives meters, returns in megahertz
float wavelengthToFrequency(float wavelength){
float frequency = (299792458.0/wavelength)*0.000001;
return frequency;
}
//// current position in millimeters
//float currentPosition(){
// float solution = (MIN_WAVELENGTH + (position*rotation)/200.0);
// return solution;
//}
// returns steps for x mm distace
long int millimetersToSteps(float millimeters){
return long(stepsPerRotation*millimeters/rotation);
}
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment