Skip to content

Commit

Permalink
Merge pull request #605 from MaslowCNC/work-on-#350
Browse files Browse the repository at this point in the history
Make it possible to extend chain by an arbitrary length
  • Loading branch information
BarbourSmith committed Feb 2, 2018
2 parents 8a995d2 + ef4a2a6 commit e8d459f
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 47 deletions.
101 changes: 101 additions & 0 deletions UIElements/measureDistBetweenMotors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from UIElements.touchNumberInput import TouchNumberInput
from kivy.uix.popup import Popup
import global_variables

class MeasureDistBetweenMotors(Widget):
'''
Provides a standard interface for measuring the distance between the motors. Assumes that both motors are in position zero at the begining
'''
data = ObjectProperty(None) #linked externally

def on_enter(self):
'''
Called when the calibration process gets to this step
'''
pass

def textInputPopup(self, target):
self.targetWidget = target

self.popupContent = TouchNumberInput(done=self.dismiss_popup, data = self.data)
self._popup = Popup(title="Set distance to move chain", content=self.popupContent,
size_hint=(0.9, 0.9))
self._popup.open()
if global_variables._keyboard:
global_variables._keyboard.bind(on_key_down=self.keydown_popup)
self._popup.bind(on_dismiss=self.ondismiss_popup)

def ondismiss_popup(self, event):
if global_variables._keyboard:
global_variables._keyboard.unbind(on_key_down=self.keydown_popup)

def keydown_popup(self, keyboard, keycode, text, modifiers):
if (keycode[1] == '0') or (keycode[1] =='numpad0'):
self.popupContent.addText('0')
elif (keycode[1] == '1') or (keycode[1] =='numpad1'):
self.popupContent.addText('1')
elif (keycode[1] == '2') or (keycode[1] =='numpad2'):
self.popupContent.addText('2')
elif (keycode[1] == '3') or (keycode[1] =='numpad3'):
self.popupContent.addText('3')
elif (keycode[1] == '4') or (keycode[1] =='numpad4'):
self.popupContent.addText('4')
elif (keycode[1] == '5') or (keycode[1] =='numpad5'):
self.popupContent.addText('5')
elif (keycode[1] == '6') or (keycode[1] =='numpad6'):
self.popupContent.addText('6')
elif (keycode[1] == '7') or (keycode[1] =='numpad7'):
self.popupContent.addText('7')
elif (keycode[1] == '8') or (keycode[1] =='numpad8'):
self.popupContent.addText('8')
elif (keycode[1] == '9') or (keycode[1] =='numpad9'):
self.popupContent.addText('9')
elif (keycode[1] == '.') or (keycode[1] =='numpaddecimal'):
self.popupContent.addText('.')
elif (keycode[1] == 'backspace'):
self.popupContent.textInput.text = self.popupContent.textInput.text[:-1]
elif (keycode[1] == 'enter') or (keycode[1] =='numpadenter'):
self.popupContent.done()
elif (keycode[1] == 'escape'): # abort entering a number, keep the old number
self.popupContent.textInput.text = '' # clear text so it isn't converted to a number
self.popupContent.done()
return True # always swallow keypresses since this is a modal dialog

def dismiss_popup(self):
try:
tempfloat = float(self.popupContent.textInput.text)
self.targetWidget.text = str(tempfloat) # Update displayed text using standard numeric format
#self.distText.text = "Dist (" + self.data.units + "):"
except:
pass # If what was entered cannot be converted to a number, leave the value the same
self._popup.dismiss()

def stopCut(self):
self.data.quick_queue.put("!")
with self.data.gcode_queue.mutex:
self.data.gcode_queue.queue.clear()

def extend(self):
dist = float(self.distToMove.text)
self.data.gcode_queue.put("G91 ")
self.data.gcode_queue.put("B09 L" + str(dist) + " ")
self.data.gcode_queue.put("G90 ")

def retract(self):
dist = float(self.distToMove.text)
self.data.gcode_queue.put("G91 ")
self.data.gcode_queue.put("B09 L" + str(-1*dist) + " ")
self.data.gcode_queue.put("G90 ")

def measureLeft(self):
self.data.gcode_queue.put("B10 L")

def pullChainTight(self):
#pull the left chain tight
self.data.gcode_queue.put("B11 S50 T3 ")
11 changes: 4 additions & 7 deletions UIElements/measureMachinePopup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from UIElements.touchNumberInput import TouchNumberInput
from UIElements.triangularCalibration import TriangularCalibration
from UIElements.adjustZCalibrationDepth import AdjustZCalibrationDepth
from UIElements.measureDistBetweenMotors import MeasureDistBetweenMotors
from kivy.uix.popup import Popup
import global_variables

Expand Down Expand Up @@ -37,6 +38,9 @@ def establishDataConnection(self, data):
self.adjustZStep.data = data
self.adjustZStep.carousel = self.carousel

self.measureMotorDist.data = data
self.measureMotorDist.carousel = self.carousel

self.triangularCalibration.data = data
self.triangularCalibration.carousel = self.carousel
triangularTestCutText = "The cuts in the corners will be about\n254 mm/10 inches from the work area edges.\n\n"
Expand Down Expand Up @@ -80,9 +84,6 @@ def slideJustChanged(self):
'''

print self.carousel.slides
#self.carousel.slides[self.carousel.index].on_enter()

if self.carousel.index == 0:
#begin notes
self.goBackBtn.disabled = True
Expand Down Expand Up @@ -287,10 +288,6 @@ def calibrateChainLengths(self):
print "calibrating"
self.data.gcode_queue.put("B02 ")

def pullChainTight(self):
#pull the left chain tight
self.data.gcode_queue.put("B11 S50 T3 ")

def updateReviewValuesText(self, *args):
'''
Expand Down
93 changes: 53 additions & 40 deletions groundcontrol.kv
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,54 @@
on_release: root.stopCut()
Label:

<MeasureDistBetweenMotors>
distToMove:distToMove
distText:distText
GridLayout:
cols: 2
width: root.width
height: root.height
GridLayout:
cols: 1
Label:
text: "Rather than using a tape measure to measure the spacing between the motors, we're going to use the chain.\n\nHook the first link from the left chain over the top tooth on the left motor\n\nThen, use the buttons to the right to extend the chain until it can reach the right motor.\n\nBe sure to keep an eye on the chains during this process to ensure that they do not become tangled\naround the sprocket. The motors are very powerful and the machine can damage itself this way\n\nHook the third link on the right motor's 12:00 tooth as shown in the picture below\n\nPull the chain tight by pressing Pull Chain Tight. You can use this button repeatedly if needed\n\nPress Measure when the chain is taught"
size_hint_x: leftCol
GridLayout:
cols: 3
Image:
source: "./Documentation/Calibrate Machine Dimensions/Chain On Left Sprocket.jpg"
Image:
source: "./Documentation/Calibrate Machine Dimensions/Chain Between Sprockets.jpg"
Image:
source: "./Documentation/Calibrate Machine Dimensions/Chain On Right Sprocket.jpg"
GridLayout:
cols: 1
size_hint_x: rightCol
Label:
Label:
text: "Dist(MM):"
id: distText
Button:
text: "100"
on_release: root.textInputPopup(self)
id: distToMove
Button:
text: "Extend"
on_release: root.extend()
Button:
text: "Retract"
on_release: root.retract()
Button:
text: 'Pull Chain Tight'
on_release: root.pullChainTight()
Button:
text: 'Measure'
on_release: root.measureLeft()
Button:
text: "Stop\nMotors"
on_release: root.stopCut()
Label:

<AdjustZCalibrationDepth>:
zAxisActiveSwitch:zAxisActiveSwitch
openZPopupBtn:openZPopupBtn
Expand Down Expand Up @@ -863,6 +911,7 @@
triangularCalibration:triangularCalibration
finishText:finishText
adjustZStep:adjustZStep
measureMotorDist:measureMotorDist

cols: 1
size: root.size
Expand Down Expand Up @@ -920,47 +969,11 @@
cols: 1
SetSprocketsVertical:
id: setSprocketsVertical
#Measure the distance between the motors
GridLayout:
cols: 2
GridLayout:
cols: 1
Label:
text: "Rather than using a tape measure to measure the spacing between the motors, we're going to use the chain.\n\nHook the first link from the left chain over the top tooth on the left motor\n\nThen, use the buttons to the right to extend the chain until it can reach the right motor.\n\nBe sure to keep an eye on the chains during this process to ensure that they do not become tangled\naround the sprocket. The motors are very powerful and the machine can damage itself this way\n\nHook the third link on the right motor's 12:00 tooth as shown in the picture below\n\nPull the chain tight by pressing Pull Chain Tight. You can use this button repeatedly if needed\n\nPress Measure when the chain is taught"
size_hint_x: leftCol
GridLayout:
cols: 3
Image:
source: "./Documentation/Calibrate Machine Dimensions/Chain On Left Sprocket.jpg"
Image:
source: "./Documentation/Calibrate Machine Dimensions/Chain Between Sprockets.jpg"
Image:
source: "./Documentation/Calibrate Machine Dimensions/Chain On Right Sprocket.jpg"
GridLayout:
cols: 1
size_hint_x: rightCol
Label:
Button:
text: 'Extend Left Chain 1mm'
on_release: root.extendLeft(1)
Button:
text: 'Extend Left Chain 10mm'
on_release: root.extendLeft(10)
Button:
text: 'Extend Left Chain 100mm'
on_release: root.extendLeft(100)
Button:
text: 'Extend Left Chain 1000mm'
on_release: root.extendLeft(1000)
Button:
text: 'Pull Chain Tight'
on_release: root.pullChainTight()
Button:
text: 'Measure'
on_release: root.measureLeft()
Button:
text: "Stop\nMotors"
on_release: root.stopCut()
Label:
cols: 1
MeasureDistBetweenMotors:
id: measureMotorDist
#Measure sled spacing
GridLayout:
cols: 2
Expand Down

0 comments on commit e8d459f

Please sign in to comment.