Friday, November 30, 2007

iPhone lego NXT control


BricX command center screen viewer+VNC+iphone=iphone lego NXT control. f'ing awesome :)
Posted by Picasa

Monday, November 26, 2007

Lego assisted I-cord knitting machine(update4)

This is a $13 plastic "i-cord" maker i bought in the kids section of a fabric store. its called an "embelish knit". Its a pretty neat mechanical device considering its made entirely of plastic. you turn a crank, feed in yarn, and you get a knit cord ("i-cord") as output. I have a project idea that will require a few hundred feet of this cord, so this seemed like the right device.




















This also seemed like an ideal task for one of my favorite toys, a lego mindstorms NXT robot set. So I attached it to a pedestal, removed the hand crank, filed a lego sleeve into a square and jammed it into where the crank used to go. instant automated cord factory! This was about all i really needed to solve my problem, an electric drill would have been probably a lot better than this (and about $170 cheaper :p).

The geek in me couldnt help but try to think of a way to completely automate the little machine. It would seem simple enough, just spool up the cord as it comes out. The problem with knitting machines is that they require lots of tension on the output line. this machine came with a 1oz weight that had to be kept on the yarn. lose the tension, and the delicate little crochet hooks would likely snap. The other issue is that because the hooks move around the center in this device, the cord spins as it comes out. This isnt a big deal for a few feet like it was designed for, but making huge pieces got to be annoying. The entire mass of already knit cord had to spin at the same rate new cord was being made. and since it was being spun, a simple winder wouldnt work. i had to figure out a way to un-spin the cord first.


So i spun the entire machine instead! Using rubber wheels i removed the yarn feed clip leaving a nice ridge that i could support from the top and bottom, letting it spin freely. but not move up and down. I removed the bottom of the machine and effectivly 'jammed' the gear for the center rotating piece in place. This meant the cord could come out of the machine un-spun, and could be easily wound up.







Keeping tension on the output cord is critical, so i rigged up a channel for the cable to come through. The lever hits a switch that is monitored. When the switch is not depressed, it turns on the winder until it sees tension.


























More Pictures:









Video and full resolution image gallery



I cant really say how long i think the poor plastic gears and bearing race will hold out, but its sofar knitted 160ft of output cord, which at about 15:1 ratio is nearly 2400ft of input yarn. not too shabby.

This is what the output cord looks like. its stretchiness depends on the input yarn.



This is a bracelet knitted on size 15 needles with some nice wool yarn i had as scrap. This is the "knit" side of the fabric.


This is the "purl" side of the same bracelet


Update: Trying to see how large a continuous ball of output i can get, as well as the largest spool i can attach. this is about 110ft of cord spooled up, and a fresh 2oz spool of yarn on the input




Update2: Some people have asked for pictures of the knitting device. as luck would have it i accidentally picked up the machine by the tube, and the tube support broke. so the knitting portion completely fell apart. boy.. was that fun to put back together.... anyways...

There are two concentric tubes, the outer tube has a bearing race cut into the side:


The center spindle has grooves cut in it that the hooks ride on:


And the hooks are flat, and have pegs that ride in the outer tubes bearing race.

Code

The code isnt clean and pretty, but it works!
This code is written in "NBC". Im not used to programming in assembly,or with threads, but this language seemed more complete than the "NXC" C interface to the language. The hardest thing to grasp were the backwards if/then/else statements.

It also uses regulated motor speeds, which are a lego firmware feature i think. It makes both of the drive motors spin at the same speed, even if they have different loads on them. sort of like a software differential.

UPDATE: Prettier better commented code below



// Embelish-knit controller
// Left and right keys adjust speed

dseg segment
KnitSpeed byte 50 // Initial knitting speed
TensionSpeed byte 5 // Initial tension speed
TensionMin byte 2 // Minimum allowed tension
TensionMax byte 20 // Maximum allowed tension
ButtonstateR byte
ButtonstateC byte
ButtonstateL byte
SwitchState byte // Switch state
crap byte // Disposable variable
exetime byte 0 // Runtime in seconds
dseg ends

thread main
TextOut(0,LCD_LINE1, 'Knitter 2.0')
TextOut(0,LCD_LINE2, 'Knit Speed:')
TextOut(0,LCD_LINE4, 'Runtime:')
TextOut(0,LCD_LINE6, 'Tension Speed:')
SetSensorTouch(IN_1)
precedes Knit,ScanButtons,Tension,TimeLoop
endt

// Drive the dual knitting machine drive motors
thread Knit
//Pretension drive. do not start knitting until there is tension
WaitForPreTension:
ReadSensor(IN_1,SwitchState)
brtst EQ,WaitForPreTension,SwitchState
KnitForever:
NumOut(0,LCD_LINE3, KnitSpeed)
OnFwdReg(OUT_AC,KnitSpeed,OUT_REGMODE_SPEED+OUT_REGMODE_SYNC)
jmp KnitForever
endt

// Watch for button presses
thread ScanButtons
WaitForButton:
ReadButtonEx(BTN2,TRUE,crap,ButtonstateR,crap)
ReadButtonEx(BTN3,TRUE,crap,ButtonstateL,crap)
ReadButtonEx(BTN4,TRUE,crap,ButtonstateC,crap)
brtst GT,RightPress,ButtonstateR
brtst GT,LeftPress,ButtonstateL
brtst GT,CenterPress,ButtonstateC
jmp WaitForButton
RightPress:
add KnitSpeed,KnitSpeed,5
jmp WaitForButton
LeftPress:
sub KnitSpeed,KnitSpeed,5
jmp WaitForButton
CenterPress:
stop 1
jmp WaitForButton
endt


// Drive and adjust the output spool drive
thread Tension
//Pretension drive. do not start until pretension is finished
PreTension:
OnFwdReg(OUT_B,TensionSpeed,OUT_REGMODE_SPEED)
ReadSensor(IN_1,SwitchState)
brtst EQ,PreTension,SwitchState
TensionLoop: // Constantly check for the state of the button press
NumOut(0,LCD_LINE7,TensionSpeed)
ReadSensor(IN_1,SwitchState)
// If the switch is down, slow down the output drive (slowly)
// If the switch isnt down, speed up output drive
brtst EQ,TensionLost,SwitchState
GainTension:
sub TensionSpeed,TensionSpeed,1
call SmoothTensionSpeed
OnFwdReg(OUT_B,TensionSpeed,OUT_REGMODE_SPEED)
//Off(OUT_B)
wait 1000
jmp TensionLoop
TensionLost:
add TensionSpeed,TensionSpeed,1
call SmoothTensionSpeed
OnFwdReg(OUT_B,TensionSpeed,OUT_REGMODE_SPEED)
wait 1000
jmp TensionLoop
endt

// Increase a variable once a second to determine runtime
// I cant believe the NXT cant do this... maybe i couldnt find it
thread TimeLoop
Runtime:
// Reset the poweroff timer
ResetSleepTimer
add exetime,exetime,1
NumOut(0,LCD_LINE5,exetime)
wait 1000
jmp Runtime
endt


// Bounds check the tension speed to prevent literal crashes
// Negative tension speed can cause permanant damage to the machine
subroutine SmoothTensionSpeed
SmoothLoop:
TextOut(0,LCD_LINE7,' ')
NumOut(0,LCD_LINE7,TensionSpeed)
brcmp GT,LowerTS,TensionSpeed,TensionMax
brcmp LT,RaiseTS,TensionSpeed,TensionMin
return
LowerTS:
mov TensionSpeed,TensionMax
jmp SmoothLoop
RaiseTS:
mov TensionSpeed,TensionMin
jmp SmoothLoop
return
ends