Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

minor adjustments #1

Merged
merged 9 commits into from Oct 23, 2011
View
@@ -28,6 +28,7 @@
#include <SoftwareServo.h>
#include "StepperModel.h"
+
#define TIMER_DELAY 64
/*
@@ -59,8 +60,10 @@
/* --------- */
-StepperModel xAxisStepper(XAXIS_DIR_PIN, XAXIS_STEP_PIN, XAXIS_ENABLE_PIN, XAXIS_ENDSTOP_PIN, XAXIS_MIN_STEPCOUNT, XAXIS_MAX_STEPCOUNT);
-StepperModel rotationStepper(YAXIS_DIR_PIN, YAXIS_STEP_PIN, YAXIS_ENABLE_PIN, YAXIS_ENDSTOP_PIN, 0, 0);
+StepperModel xAxisStepper(XAXIS_DIR_PIN, XAXIS_STEP_PIN, XAXIS_ENABLE_PIN, XAXIS_ENDSTOP_PIN,
+ XAXIS_MIN_STEPCOUNT, XAXIS_MAX_STEPCOUNT, 200.0, 16);
+StepperModel rotationStepper(YAXIS_DIR_PIN, YAXIS_STEP_PIN, YAXIS_ENABLE_PIN, YAXIS_ENDSTOP_PIN,
+ 0, 0, 200.0, 16);
SoftwareServo servo;
boolean servoEnabled=true;
@@ -110,11 +113,13 @@ void setup()
Timer1.initialize(TIMER_DELAY); // Timer for updating pwm pins
Timer1.attachInterrupt(doInterrupt);
+#ifdef AUTO_HOMING
xAxisStepper.autoHoming();
xAxisStepper.setTargetPosition(0.);
commitSteppers(maxFeedrate);
delay(2000);
xAxisStepper.enableStepper(false);
+#endif
}
void loop() // input loop, looks for manual input and then checks to see if and serial commands are coming in
@@ -499,3 +504,5 @@ void drawArc(double centerX, double centerY, double endpointX, double endpointY,
}
}
+/* Make life easier for vim users */
+/* vim:set filetype=cpp: */
View
@@ -18,14 +18,17 @@
#include "StepperModel.h"
#include "WProgram.h"
-const double kStepsPerRevolution=200.;
-const int kMicroStepping=16;
/*
* inEnablePin < 0 => No Endstop
*/
-StepperModel::StepperModel(int inDirPin, int inStepPin, int inEnablePin, int inEndStopPin, long minSC, long maxSC)
+StepperModel::StepperModel(int inDirPin, int inStepPin, int inEnablePin, int inEndStopPin,
+ long minSC, long maxSC,
+ double in_kStepsPerRevolution, int in_kMicroStepping)
{
+ kStepsPerRevolution=in_kStepsPerRevolution;
+ kMicroStepping=in_kMicroStepping;
+
dirPin = inDirPin;
stepPin = inStepPin;
enablePin = inEnablePin;
@@ -46,17 +49,19 @@ StepperModel::StepperModel(int inDirPin, int inStepPin, int inEnablePin, int inE
currentStepcount=0;
targetStepcount=0;
- steps_per_mm = (int)(kStepsPerRevolution/(45.*M_PI))*kMicroStepping; // default value for a "normal" egg (45 mm diameter)
+ steps_per_mm = (int)((kStepsPerRevolution/(45.*M_PI))*kMicroStepping+0.5); // default value for a "normal" egg (45 mm diameter)
enableStepper(false);
}
void StepperModel::resetSteppersForObjectDiameter(double diameter)
{
// Calculate the motor steps required to move per mm.
- steps_per_mm = (int)(kStepsPerRevolution/(diameter*M_PI))*kMicroStepping;
+ steps_per_mm = (int)((kStepsPerRevolution/(diameter*M_PI))*kMicroStepping+0.5);
if(endStopPin>=0)
{
+#ifdef AUTO_HOMING
autoHoming();
+#endif
enableStepper(false);
}
else
@@ -148,7 +153,8 @@ void StepperModel::doStep(long intervals)
digitalWrite(stepPin, LOW);
}
}
-
+
+#ifdef AUTO_HOMING
void StepperModel::autoHoming()
{
enableStepper(true);
@@ -163,3 +169,4 @@ void StepperModel::autoHoming()
currentStepcount= minStepCount-16;
}
+#endif
View
@@ -18,6 +18,9 @@
#ifndef STEPPERMODEL
#define STEPPERMODEL
+// Uncomment if You have Autohoming:
+//#define AUTO_HOMING
+
class StepperModel
{
private:
@@ -30,7 +33,10 @@ class StepperModel
long minStepCount;
long maxStepCount;
double steps_per_mm;
-
+
+ double kStepsPerRevolution;
+ int kMicroStepping;
+
volatile long currentStepcount;
volatile long targetStepcount;
@@ -43,11 +49,16 @@ class StepperModel
volatile long counter;
double targetPosition;
- StepperModel(int inDirPin, int inStepPin, int inEnablePin, int inEndStopPin, long minSC, long maxSC);
+ StepperModel(int inDirPin, int inStepPin, int inEnablePin, int inEndStopPin,
+ long minSC, long maxSC,
+ double in_kStepsPerRevolution, int in_kMicroStepping
+ );
void resetSteppersForObjectDiameter(double diameter);
+#ifdef AUTO_HOMING
void autoHoming();
+#endif
void setTargetPosition(double pos);
View
@@ -0,0 +1,25 @@
+# Gnuplot Session
+#
+# Erste Spalte=x, Zweite=y
+# Ei Spitze zeigt nach rechts (positive x)
+#
+# plot "egg-displace.dat" using 1:2 title "Ei"
+# ==> graph looks like a parabola
+# f(x)=a*x*x + b*x + c
+# fit f(x) "egg-displace.dat" using 1:2 via a,b,c
+# a=0.00795338
+# b=0.0734545
+# c=0.15711
+# plot "egg-displace.dat" using 1:2 title "Ei" with lines, f(x)
+# ==> fits reasonable well
+-25 3
+-20 2
+-15 1
+-10 0.5
+-5 0.1
+0 0
+5 0.5
+10 1.5
+15 3
+20 5
+25 7
View
@@ -0,0 +1,125 @@
+#!/usr/bin/python
+
+# Feeds a gcode File to the SphereBot.
+#
+# Write a line to the serial device and wait for an "ok" response.
+
+# prerequisite: http://pyserial.sourceforge.net
+# Installation on Ubuntu: sudo aptitude install python-serial
+
+
+
+
+# Configure:
+BAUDRATE = 57600
+DEVICE = "/dev/ttyUSB1"
+DEVICE = "/dev/tty.PL2303-00001004"
+DEVICE = "/dev/tty.PL2303-00004006"
+
+# End configuration
+
+
+
+import sys
+import serial
+import re
+from optparse import OptionParser
+
+def y_displacement(x):
+ # look into file egg-displace.dat for documentation
+ return (0.00795338*x*x + 0.0734545*x + 0.15711)
+
+lastX = 0.0
+
+def correctDisplacement(lineIn):
+ # extract x and y
+ # calculate new y
+ # return line with alter y
+
+ global lastX
+ foundY = False
+
+ line = lineIn.upper()
+ words = pattern.findall(line)
+ for word in words:
+ if word[0] == 'X':
+ lastX = eval(word[1:])
+
+ if word[0] == 'Y':
+ y = eval(word[1:])
+ foundY=True
+
+ if foundY:
+ y = y + y_displacement(lastX)
+ else:
+ return lineIn
+
+ lineOut=""
+ for word in words:
+ if word[0] == 'Y':
+ lineOut = lineOut + "Y{0}".format(y)
+ else:
+ lineOut = lineOut + word
+
+ return lineOut
+
+def penChange(lineIn):
+ # Test Line for a Pen change request (M1)
+ # If true, wait for user input
+
+ if penChangePattern.match(lineIn):
+ raw_input('Change pen ... press <Return> when finished ')
+
+
+######################## Main #########################
+
+parser = OptionParser(usage="usage: %prog [options] gcode-file")
+parser.add_option("-e", "--egg-displace", dest="wantDisplaceCorrection",
+ action="store_true", default=False,
+ help="Correct displacement if drawn on a egg. The tip of the egg is pointing right hand.")
+parser.add_option("-d", "--dont-send", dest="wantToSend",
+ action="store_false", default=True,
+ help="Dont send GCode to SphereBot")
+
+(options, args) = parser.parse_args()
+
+
+
+if len(args) != 1:
+ parser.error("incorrect number of arguments: need one gcode file to send to the sphereBot!")
+
+
+if options.wantDisplaceCorrection:
+ pattern = re.compile('([(!;].*|\s+|[a-zA-Z0-9_:](?:[+-])?\d*(?:\.\d*)?|\w\#\d+|\(.*?\)|\#\d+\=(?:[+-])?\d*(?:\.\d*)?)')
+
+penChangePattern = re.compile('^M01')
+
+fileToFeed = args[0]
+gcode = open(fileToFeed, "r")
+
+if options.wantToSend:
+ sphereBot = serial.Serial(DEVICE, BAUDRATE, timeout=30)
+
+currentLine = 0.0
+lines = gcode.readlines()
+totalLines = len(lines)
+for line in lines:
+ currentLine = currentLine + 1
+
+ print line, "({0:.1f}%)".format((currentLine / totalLines)*100),
+
+ penChange(line)
+
+ if options.wantDisplaceCorrection:
+ line = correctDisplacement(line)
+ print ">> ", line,
+
+
+ if options.wantToSend:
+ sphereBot.write(line)
+
+ response = sphereBot.readline()
+ while response[:3] != "ok:":
+ print " ", response,
+ response = sphereBot.readline()
+
View
@@ -0,0 +1,39 @@
+#!/bin/sh
+## \
+exec tclsh "$0" ${1+"$@"}
+
+# Feeds a gcode File to the SphereBot.
+#
+# Write a line to the serial device and wait for an "ok" response.
+#
+# Configure:
+
+set BAUDRATE 57600
+set DEVICE /dev/ttyUSB1
+
+
+# End configuration
+
+
+set fileToFeed [lindex $argv 0]
+
+
+set fdIn [open $fileToFeed]
+set fdOut [open $DEVICE r+]
+fconfigure $fdOut -mode $BAUDRATE,n,8,1
+
+
+while {[gets $fdIn line] >= 0} {
+ puts $line
+ puts $fdOut $line
+ flush $fdOut
+ while {[gets $fdOut answer]} {
+ puts "\t$answer"
+ if {[regexp {^ok:} $answer]} {
+ break
+ }
+ }
+}
+
+close $fdIn
+close $fdOut
View
@@ -0,0 +1,60 @@
+#!/usr/bin/python
+
+# Some usfull gcode info - manipulation functions
+#
+
+# prerequisite: http://pyserial.sourceforge.net
+# Installation on Ubuntu: sudo aptitude install python-serial
+
+
+
+
+# Configure:
+
+# End configuration
+
+
+
+import sys
+import re
+import serial
+
+class Range:
+ def __init__(self):
+ self.min = 999999
+ self.max = -999999
+
+ def __str__(self):
+ return 'Range({self.min}, {self.max})'.format(self=self)
+
+ def adjust(self, value):
+ """
+ If value is out of range expand range
+ """
+ if value > self.max:
+ self.max = value
+ if value < self.min:
+ self.min = value
+
+
+fileToFeed = sys.argv[1]
+gcode = open(fileToFeed, "r")
+
+
+xRange = Range()
+yRange = Range()
+pattern = re.compile('([(!;].*|\s+|[a-zA-Z0-9_:](?:[+-])?\d*(?:\.\d*)?|\w\#\d+|\(.*?\)|\#\d+\=(?:[+-])?\d*(?:\.\d*)?)')
+
+lines = gcode.readlines()
+for line in lines:
+ line = line.lower()
+ words = pattern.findall(line)
+ for word in words:
+ if word[0] == 'x':
+ x = eval(word[1:])
+ xRange.adjust(x)
+ if word[0] == 'y':
+ y = eval(word[1:])
+ yRange.adjust(y)
+
+print "x=", xRange, " y=",yRange
Oops, something went wrong.