Thursday, March 11, 2010

Rotary Dumper springs images and Coupler close-up video

Stretched out the springs and the car stays on the rail. They look awful, but at least they work now.

Upside down and on the rail.



Close-up video of rotating coupler

Sunday, February 28, 2010

Bridges and Crossings

Intial bashing of Bachman and Model Power crossings... prior to servos and LEDs.

a couple of bridges - glued together Atlas bridges. Dreaming of modeling the NS Wabash lift bridge at Hannibal MO. It has a 400+' lift, a 100+' panel, 1 250+' truss and 4 ~175' trusses. That works out to over 17 real feet at HO scale.

Wednesday, February 17, 2010

2 level car carrier in progress


One side and the other of an undecorated Walthers, after painting. Waiting for the muse to deliver the iconic image and script to decal onto the panels.

Sunday, February 14, 2010

Electrical Measurements part 3 - later that same day

Regulated power supplies deliver a flat voltage :) Hooked in line with a rheostat (as in a fan speed control) should adjust the voltage from Lo 0 .. 10..15 volts

GSC 10 amp regulated 14+ volts multimeter about 10 volts on an oscilloscope.

Pyramid 2.5 amp delivers about 10 volts on an oscilloscope.

Electrical Measurements part 2

Hooked up some other train transformers. Makes me wonder how they pass electrical inspection to get the stamp of approval. Will hook up some motor controllers some day.. just reading the information on them though: they seem to all output PWM :( Maybe just use a large rheostat on a 12 or 24 volt power supply as they seem to output a clean flat voltage.

Bachman at about 6 volts

Model Power at about 10 volts

Tuesday, February 2, 2010

Electrical measurements

Servo amperage:
Name (amps) [torque]
Hitec HS 50 (0.2) [8.3oz] {smaller than HS55}
Hitec HS 55 (0.19) [15.3oz]
Hitec Digital 5045 (0.28) [13.4oz]
Parallax Futaba S148 (0.56) [?oz uhm, more than those- a standard size servo]

a multimeter hooked in line using a modified servo wire ( red wire cut so the meter could be in line). The servos were operated in their functional duty : Lifting a rocket tube or moving a 4 unit-train of cars. None were 'stalled' so these measurements have only a relative context.


Locomotive Power
an RC ESC only works with a radio, Never mind- it outputs a Voltage Clipped Down from the 7.2 V input battery to whatever level is set for the motor speed.


MRC 9500 (HO train transformer) at about 2 volts
has a voltage spike twice the normal voltage : ? to 'bump' the locomotive? i dunno, it was a SHOCK to see it :(

MRC done again (17 feb) to check various voltage levels. They all have a 'bump' decreasing as the voltage rises to 9 volts... above 9 volts the signal is the same ... a multimeter reads increasing voltages... i dunno what that spike was in the previous view... it looks to be a different time and or voltage amount per grid...

PWM servo signal was of course just spikes of voltage and varying in voltage level, the variation due to the length of the signal variation 'adding' up to different levels i guess

Motor controllers : ? TBD ? investigate the output waveform ... hopefully a level voltage that will change IAW the desired voltage.

Saturday, January 30, 2010

HO train action ideas

A collection of thoughts on things that go bump in the night on the train set.


HO Action - Interaction . . . . . . . . . . . . Page 1 of 3
Loading - Unloading . . . . . . . . . . . Page 1 of 3
Granular [Coal, gravel, Wood chips, grain]Page 1 of 3
Objects . . . . . . . . . . . . . . . Page 1 of 3
Liquid. . . . . . . . . . . . . . . . Page 1 of 3
Ships: . . . . . . . . . . . . . . . . . . Page 1 of 3
Coal-Ore-Grain. . . . . . . . . . . . Page 1 of 3
Container ship . . . . . . . . . . . Page 1 of 3
Oil tanker. . . . . . . . . . . . . . Page 1 of 3
Barge. . . . . . . . . . . . . . . . . . . Page 1 of 3
Aircraft . . . . . . . . . . . . . . . . . Page 2 of 3
Train - Automobile (RR crossing gates) - Page 2 of 3
Landscape action . . . . . . . . . . . . . Page 2 of 3
Switches - Signals - Railroad Yard - Block direction of travelPage 2 of 3
On train . . . . . . . . . . . . . . . . . Page 2 of 3
Locomotive. . . . . . . . . . . . . . Page 2 of 3
Rolling stock action. . . . . . . . . Page 2 of 3
Paper Mill cars . . . . . . . . . . . . . . . . Page 2 of 3
Inbound. . . . . . . . . . . . . . . . . . Page 2 of 3
Outbound . . . . . . . . . . . . . . . . . Page 3 of 3
Ethanol cars. . . . . . . . . . . . . . . . . . Page 3 of 3
Inbound. . . . . . . . . . . . . . . . . . Page 3 of 3
Outbound . . . . . . . . . . . . . . . . . Page 3 of 3
Steel Mill. . . . . . . . . . . . . . . . . . . Page 3 of 3
Inbound. . . . . . . . . . . . . . . . . . Page 3 of 3
Outbound . . . . . . . . . . . . . . . . . Page 3 of 3
_____ Factory . . . . . . . . . . . . . . . . . Page 3 of 3
Inbound. . . . . . . . . . . . . . . . . . Page 3 of 3
Outbound . . . . . . . . . . . . . . . . . Page 3 of 3



HO Action - Interaction
[] Loading - Unloading
Granular [Coal, gravel, Wood chips, Ore-Taconite, Corn-grain] into Hoppers-Gondolas,
Life-Like Gravel-Coal loader : dump into car - Life-Like Gravel-Coal dump from car into bin
Walthers Rotary dumper : rotate car to dump load into bin
Rotary dumper: lazy susan ends, geared hold downs, chain drive rotation, gear drive or pulley pulled positioner, ‘dummy' locomotive in front-actually pushed by one in rear until past the dumper- then rear loco uncouples and positioner moves the train cars... a positioner on both sides of the dumper - take turns actually moving the cars - they return while the other one is moving train and dumper is dumping. (Oops too complicated -unless multiple controllers are used .. Might be possible using a C-AVR controller)

Wood chips: Sawdust: Rotary dumper -into conveyor -to pile beside Plant building- sucked - falls down into pile on next level- crane loads into train cars... Sawdust-pencil shavings are VERY light, maybe use ?____? dyed a light color...

Objects onto flatcars, into boxcars, into gondolas,
Crane log loader-unloader
Steel recycler crane unloads train cars (scrap steel / old flattened cars) into the ‘crusher'
Container loading-unloading

Liquid into tank cars-from ship-to refinery [Valves, pumps, visible liquid, ___ made by____ ]


[] Ships:
Coal-Ore-Grain ship : funnel-dumped into - craned out
Container ship - loader-unloader (Walthers: $800) magnet crane
Oil tanker - derricks - moving level tank

[] Barge
Barge MUST be *secured* to keep from making waves and sinking when loaded-unloaded.

I Could not figure out how to make a FUNCTIONAL coal flood loader so ... : Crane scoop-lifts coal from barge straight into funnel coal loader into train cars, tug pushes barge around-under lift bridge, around to be loaded from rotary dumper dumping coal down slide.

Grain barge - hopper - conveyor - to train cars - to Ethanol plant - to liquid fuel in train cars to valve operation loading-unloading.

‘Faller' Vehicles load onto dock - onto barge.
Train cars load onto dock - onto barge.


[] Aircraft
-HO aircraft -helicopters fly around
-Hover craft - flying saucer: 4 gyro-stabilized turbines for lift- 1 in enter for guidance
-Rockets on train- on ground-target train cars that explode (USB camera guided)

[] Train - Automobile (RR crossing gates) -
HO scale slot cars roadway and train track that can drive over each other by Lifelike as of Nov 2009. Faller vehicles: wire-cars

[] Landscape action : continually or signaled on/off by train or by movement detection sensors. Landscape lights, Hotel Elevators going up and down, houses burning, Factories fuming, Carnival rides, Wind mill, wind turbine, water flowing... -Water comes in from a water fall, goes around {barge canal} {Shipyard docks} and out and down a drain- to be pumped up to the waterfall.
Camera on train displayed on a 'Drive-in' theatre screen.
People move: magnets on a glass sidewalk.

[] Switches - Signals - Railroad Yard - Block direction of travel .. DCC / computer controlled trains, switches, signals... -Locomotive round-table

[] On train
. Locomotive: Lights, Sound, Smoke
. Rolling stock action: Lights in cars, Searchlights, Helicopter takes off, Missiles raise and fire... uhm all military macho things, huh. Doors swing open. Ammo box explodes apart when hit by missile launched from other train car or land based launcher.



[] Paper Mill cars (Info combined from various web pages...)
Actual cars depend on type of plant and paper produced.
Inbound: (logs, sawdust, wood pulp, cotton)
logs on flatcars
Wood Chip gondolas ... Require Netting over them to keep the chips from blowing off-away.
Athearn older small 40'? wood sided?
Walthers HO Scale "Gold Line" Ready-to-Run 61' Wood Chip Gondola Car (flat bottom box)
"Freight Car America" Wood Chip tub gondola:16' tall, 67.5 inside 72' coupler ends [2.2 x 9.93]
Rotary Wood chip gondola looks like a Coal gondola except it is 19' longer and 3' taller
Baled pulp-Boxcar (various)
Recycled Paper or Cardboard-Boxcar (various)
Bales of cotton on flatcars (various)
baled cotton pulp-Boxcar (various)

Machinery-Boxcar or flatcar (various)

COAL:
Quad hopper and Bethgon tub same size, tub increases the capacity : 13'tall 53'long [1.8 x 7.3]

oil for the boiler and steam plant
-Chlorine-Tankcar (Atlas Walthers)
Hydrogen Peroxide, LIME,, Salt Cake
-Sulfuric Acid - Hydrochloric Acid-Tankcar (Atlas Walthers)
-Kaolin Slurry-Tankcar (Atlas Walthers)
Covered Hopper: Kaolin Clay from Saunderville in the Southern US
funnel flow tank cars from walthers or Atlas lettered for any of the kaolin producers, ECC,
HUBER, Georgia Kaolin, Engelhard
-Sodium Chlorate-40\' Alumn. Covered Hoppers (no model av.)
-Sodium Hydroxide -Tankcar (Atlas or Walthers or MDC)
-Caustic Soda-PD or airslide Covered Hoppers (Walthers, Atlas and others.)
-Calcium Carbonate Slurry-Tankcar (use the Kaolin cars by Walthers or Atlas)
-Corn Starch-Tankcar or PD covered Hoppers (no real accurate models, but Walthers or MDC will do for now)
-Titanium Dioxide-Tankcar (short cars that there are no models of currently ?8K "Staley" ‘can' cars?)
-Latex or other Plastic coatings-Tankcar (various)



Outbound:
Finished Paper-Boxcar (Various, Hi-Cubes preferred)
"Tall Oil"-Tankcars (Atlas, Walthers, and MDC tankcars)
Turpentine-Tankcars (Atlas, Walthers or MDC)
"Black Liquor"-Tankcars (Atlas, Walthers or MDC)


Ethanol cars (Info combined from various web pages... mostly Walthers)
Inbound: Covered hoppers
Outbound: Fuel-tankers

Steel Mill
Inbound: Coal, ore, coke, ...
Outbound: Coil cars, gondolas , ...

_____ Factory ...
Wood River Oil refinery
Wood River GeoDome auto carrier repair shop
Tyson meat plant
Cotton bales to a Cotton Gin
Waste recycling plant : Garbage, steel, cars, ...

Inbound: ___, ...

Outbound: ___, ...

Wednesday, January 27, 2010

DCC is really AC DCC (or What happened)

According to : S-91-2004-07.pdf Section C ...
The baseline method for providing the power to operate locomotives and accessories, which shall be supported by all Digital Command Stations and Digital Decoders, is by full-wave rectification of the bipolar NMRA digital signal within the Digital Decoder[7]. ...

If decoders actually did this, then DCC would actually be DC DCC, however, the problem is that footnote 7 is where they let the Devil into their Heaven.

[7] Alternate means for supplying power are acceptable, provided that Digital Command Station power units are capable of producing the baseline track signal, and Digital Decoders are capable of operation from the baseline track signal as described by this standard.

so they all can go to Hell AFAIK

... from Marcus Ammann’s DCC for Novices web page :
Pulse Width Modulation, PWM, is a cheap and easy to manufacture technique to control DC motors. Some DC power packs and most DCC decoders use this technique.
...
PWM frequency: Early “noisy” decoder - about 2 kHz. Later “quiet” decoders - above 16 kHz. Later Sound decoders - 25 kHz.
...
and they continually 'improve' in an effort to correct the initial fatal flaw of PWM on a DC motor.
...

No matter that I disagree with the AC-DCC decoder implementation, there are items of interest:

DCC code for AVR is available at Arduino Playground in the Exhibition section by Michael Blank:
a "one loco" command station and throttle . Incredible open hardware designs and open source software by Wolfgang Kufer at OpenDCC , although a lot of it is still in German... JMRI is an open source Windows-Mac-Linux Java program to run trains - interfaced with the DCC system.

and still ... i think using an RC car BEC as the speed control for a normal DC locomotive and power provider for the AVR board/servos actually provides a solution that would enable controlling the locomotive in interaction with AVR controlled loading-unloading operations. Direct control of the locomotive would be more responsive than transmitting messages to a Command station that then transmits them to the locomotive decoder. Now I need to hook up the oscilloscope to one and make sure they actually have a DC signal for the motor and not PWM as used for the servos, but servo control would be sent from the RC receiver.... or maybe a Motor controller that does not use PWM power.

Saturday, January 23, 2010

Missile launcher flatcar


Add Image
The black box on a flat car holds the 4.8 volt battery for the servo. The gray box holds the controller and its 7.2 volt battery, the remaining space on the flatcar allows room for the missile to extend past its own flatcar. The missile is on a bashed together 40 and 50' flatcar. The servo in the center of the car - beneath the rocket, raises-lowers the rocket. Another simple and crudely done addition to the missile fleet. Someday the fleet will fly.

Rotary dumper review

rotary dumper base:
The base needs to hold the dumper and allow the 'coal' to fall through unimpeded... basically not have a base - just walls supporting the dumper.

rotary dumper gears:
Gears need to be able to turn the dumper without getting clogged from the 'coal' and not pull the dumper off its rotation. a motor-servo turning the gears. Bearings or wheels supporting the dumper in its rotation - also not to be clogged with 'coal'

rotary dumper clamps:
A rotary dumper needs a motor to move the clamps that hold down the car when rotated. The springs are too weak, a servo is too- it will 'rebound', the clamps need to be able to move UP high enough for a locomotive to drive through and DOWN strongly enough to actually hold the car when upside down.

Train Positioner: a cart on rails that holds a micro servo arm, moved by wires on a pulley or a servo on the cart driving against a gear rack. Great parts source : McMaster-Carr Supply Company

Wednesday, January 13, 2010

Shopping for a microcontroller

After a time limited search the Atmel AVR seems very promising. PICs are dead to me, wasted money and time learning their inanities. It seems microcontrollers require a program to write the code (compiler) and one to download the code into the chip (programmer). Most chip boards as of 2010 have a USB connector to download the program into their Flash RAM so placing the chip in/out of a hardware chip programmer is no longer required. Arduino distributes their free IDE (Integrated Development Environment)- compile and program the chip interactively. Easy and Free : i like it. they provide many tutorials - code examples - libraries. Arduino designs several AVR board types, ranging from the Nano to the Mega :)

Atmel (manufacturer) Developer of the AVR
AVR 32K 64K 128K 256K Flash Ram to store the program

Arduino
Arduino Nano 3.0 (ATmega328) {could fit inside a HO train car:)}
Arduino Mega (ATmega1280)
Arduino's can be programmed on a Linux Mac PC
SmartProjects (Italy) handles the manufacturing of most of the Arduino products: sold globally from the stores listed on the Arduino website. Gravitech makes the Nano and sells Arduino products. SparkFun makes the Arduino LilyPad, Pro, and Mini Pro and sells Arduino products, accessories - sensors and provides code, datasheets, and tutorials.

AXON (ATmega640) "Designed by and for a robotics hobbyist" has many tutorials and a free collection of programming tools on-line.

Digilent Cerebot Plus : Atmel ATmega2560
not really sure if their free programmer does what, yet.
Digilent also sells FPGA Field programmable gate arrays boards : Xilinx Spartan-3E FPGA which has 32MB Micron DDR SDRAM, 16MB Numonyx StrataFlash, VGA, PS/2, RS-232, 10/100 Ethernet (i have no idea what it takes to program this... from their ad: "designing digital circuits in VHDL or Verilog and using block diagrams, simulate them, and quickly and easily download them") .. so not a microcontroller anymore eh.


ARM ...microcontrollers requires LINUX, and not sure what else...
inex ARM7TDMI-S
Roboporium ARM-920T

and many more makers TI INTEL MOTOROLLA MMM... designed for corporations that purchase 1000s i guess ...

Seems like at this price/point a netbook that had many I/O (sensor) lines and Servo/Motor controllers would be what would interest me... or run an AVR microcontroller with commands over a USB-serial line from the netbook. Most netbooks have 1G ram, 1.66GHz processor, 160GB hard drive, a 'real' screen and keyboard, webcam-microphone-speakers, USB and several types of networking: hardwired Ethernet, wireless...

All Cleaned up and decorated.


All the wires are hidden away and everything is working ok. "The lights are on but nobodys home." Well, the dumper clamp-springs are not strong enough to hold the car upside down against gravity, so am design-building a hold down clamp for the cars as they exit the dumper. Tested by holding the dumped car with my hand and that works... the couplers stay coupled and the car gets back on the track.


[the following was added 2010jan16]

Note the servo and yellow wire to the right of the dumper :) It works. This makes 6 servos used to unload a coal train.
1. positioner wheel mover
2. positioner arm grabber
3. car gate arm stopper
4. car brake axle grabber
5. rotary dumper rotation
6. exit wire hold-down
One of the buttons on the BN control box is no longer connected to the controller.. the resistor wire is snipped and the pin is used for the exit servo. The wiring on the hard wired controller has become embarrassingly atrocious. hmm, spellcheck does not like the word positioner, o well, it can be found on the web.

Wednesday, January 6, 2010

Banned from Parallax

After posting my rotary dumper project the resident cyber bully succeeded in getting me banned from the forum after several posts. It took a while but he is still there insulting me after i am gone. Apparently he can insult me and violate every one of their 'netiquete' rules, however i cannot insult back. There is no validation of answers to questions, so be advised it is a 'public' forum not a repository of knowledge. I guess it is just as well, since the BS2 boards will not fit in an HO train car i will be shopping elsewhere for my next controller. It was real and it was fun but it was not real fun afterall. In case the code is also banned... the next 2 (actually previous) posts will contain the code for anyone that can use it to operate their rotary dumper. One for the Parallax BOE and one for the homebrew board. The homebrew board has a little more code as i added a 5th servo and an IR detector to read commands from a SONY DVD remote control. That code could of course be used on the BOE... just be advised the pins are physically almost mirror reversed between the two boards.

Code for BS2 Homebrew board

' {$STAMP BS2}
' {$PBASIC 2.5}
' Dump4everHB4-1.bs2 as of 2009dec29 from Dump4everV3.bs2
' reWritten for a Homebrew Stamp board
' V1 started in 2009November
'Thanks: Wayne Roderick DumpA403.bs2 04/03/2000 tetonsl@ida.net
' V2 Changed Positioner code to try to get the push bar to place car OVER brake
' V3 Changed Pusher bar to a Coupler Grabber
' HB4 Homebrew Stamp board and added IR Remote and another Servo
'HB4-1 Hardwired a RESET button on the Box
'Emergency Stop button code removed as OBE
'Removing IF (emergencyStopBtn=1) THEN END
'Cleared enough code to use Make_Music :) NotesAndDurations.bs2
'Initialize Servo pins to LOW :
'PULSOUT ArmServo, 466 ' Arm UP 'dunno what step does to leftovers
'PAUSE 20
'DIR13=0 'remove pulse to insure stop
'that would make it an antennae, PULSOUT returns it to previous: LOW output

Copyright DATA "I","v","a","n","H","e","r","r","i","n","g","2","0","1","0"
' What's a Microcontroller - NotesAndDurations.bs2
' Play the first few notes from Frere Jacques. 14
Notes DATA "C","D","E","C","C","D","E","C","E","F","G","E","F","G","Q"
Durations DATA 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 2

'Beethovans 5th 9
'Notes DATA "G","G","G","e","P","F","F","F","D","Q"
'Durations DATA 8, 8, 8, 2, 8, 8, 8, 8, 2

' Twinkle Twinkle 14 fudged durations, i dunno
'Notes DATA "C","C","G","G","A","A","G", "F", "F", "E", "E", "D", "D", "G","Q"
'Durations DATA 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 8
WholeNote CON 2000


' Controls Five servos of an automated HO scale rotary dumper
' 1. Dumper motor is a Parallax Futaba limitless servo.
' It has a PULSOUT dead band (758..761 x2usec) 1515..1522.
' Values near the deadband control the speed that reachs a maximum
' of about 60RPM at PULSOUT values of about +/-40. 1 RevPerSecond.
' The travel limits are controlled with a single flapper switch
' flapped at 2 positions Reverse and StopatTop
' 2. Positioner motor is a Parallax Futaba limitless servo.
' It has a PULSOUT dead band (756 TO 760 x2usec) 1512 to 1520 .
' 'ditto' has 2 flapper switches :PositionerAtEnd and PositionerBack
' 3. Positioner Arm motor is a Parallax Futaba servo.
' It rides on the Positioner cart and raises - lowers its arm
' to be the positioner car coupler grabber
' 4. Brake is an old Futaba servo.
' It is under the track and raises its arm
' to hold the car in the correct position.
' 5. Positioner other side incoming brake
' hitec retract servo 1430 : 715 is brake on ... 1440:720 is open

' Servos, LEDs, PhotoResist, Buttons, Switches are connected to 3-pin posts
' and connected from board to item by a 3 wire servo extension

' The red green LEDs will be flashing when system is powered up
' and a reset cycle has been done. It will flash idiot lights
' when the system is waiting for a train: checking Buttons

' After Initialization-Power on - the cars are placed in position
' Three Buttons on a Servo extension in a bashed Coalgon
StartButton PIN 15 'white-yel wire
'Just in case EmergencyStopBtn removed due to RESET button on Box
Position1CarBtn PIN 14 'red wire
'Used when done to dump last car(s) pulled onto dumper by other loco
RotateDumper1Btn PIN 13 'black wire

'Flapper switches for servo movement limits
'Positioner limits
PositionerAtEnd PIN 12 'black wire Positioner Near Dumper
'A B hehehe - this will haunt me right ?
PositionerBack PIN 11 'red wire Positioner at back
'1 switch-sensor used to Reverse and Stop at Top Dumper
DumperSensor PIN 10 ' white wire

'not really coded - just flashing lights
GreenLight PIN 9 'yel-white wire
'No error detection AFAIK so just for funsies
RedLight PIN 8 'red wire , black of set is ground

'Photo diode light detector
CheckLight PIN 7 'its own wire set, only using 2 wires
Siren PIN 6 'on board only- sounds at end of cycle
'IR detector for a hand held TV remote control IAW Three Buttons
IRDetector PIN 5 'its own wire set- Currently ON BOARD
'uses all 3 White is Signal,R-,B+ ---
'it Matches the Detector inputs S-+ NOT the Servo S+-

'Additional Servo Positioner Retract servo-
'but not needed if the Positioner actually Works ...
'used to Stop the incoming train cars at correct location
RetractServo PIN 4
'4 Servos on Pins: 12 :Positioner, 13: Arm, 14 : Brake, 15 : Dumper
PositionerServo PIN 3
ArmServo PIN 2
BrakeServo PIN 1
DumperServo PIN 0


'THE PLOT
'A Unit train arrives and the Power de-couples from front
' and runs around dumper to wait for its train to be dumped.
' The train is Pushed to Positioner by Industry Power.
'The Positioner is near dumper, Arm and the Brake are Down.
'the Start Button is Pressed
'Position1Car: Push 1 car forward and Brake it,
'Check if more cars (Light detector) {it is needed here the first time...}
'then go into the lOOP
'lOOP:
'Push 1 car forward and Brake it, the car before is Now in dumper
'Rotate Dumper
'Check if more cars (Light detector )
'Repeat LOOP until Detector Exits the Loop : no more cars
'Done: Retract brake and raise Positioner a LITTLE bit
' as it has GRABBED the Coupler
' Positioner Near Dumper and the Arm raised a LITTLE
'Thus at end 1 car on ready-track , 1 car On dumper : IS dumped
'Pull Last car through-onto Dumper from other end with Power locomotive.
' Then Dump Last car Using the 3rd Push button to activate Dumper

'global variables Byte : Value can be 0 to 255
counter VAR Word ' Value can be 0 to 65535
positionerSpeed VAR Byte
positionerSpeed=20 'Set here to change all places easier
positionerStop VAR Word
positionerStop=758 'center of dead band
brakeSet VAR Word
'/////////////////////////////////////////////////////
'Brake ups and downs
'1000 is Topped OUT : 500 : it hits the track above
'1050 is just clear of Top Out : 525
'1130 '1161 it Lifts the wheels from the track 580 or 581 582
'1136 ...1140 is Good and Tight
'567 '1140 : 570 '1164 : brakeSet=582
'1145 '1166 BrakeSet is just before : 583
'1150 ...is caught but...
'1200 is caught but way loose 600
'1500 is Below track : 750 normal centered
'1800 is bottom out:900
'Using HPP-21
'the SERVO CHANGES ??? 582 start, now 572
'1130 565 1134 567 1140 570 glitching 1144 572 SET 1150 575:loose
'in code ... 572 is still loose 565 IS OFF the rail..but o so sweetly 2009dec28
'/////////////////////////////////////////////////////
brakeSet= 565 '565 567 570 572 582 583 'Brake holds the axle Tight

'Photo resistor detection of train cars to dump
carShadow VAR Word
' >1600 is a car <50 is no car , THIS is middle low
carShadow=500
time VAR Word 'IF (time < CarShadow) THEN NoMoreCars=1
noMoreCars VAR Bit

'for Sound .. some of the other variables are "reused"
duration VAR Word
frequency VAR Word
noteLetter VAR Byte

'IR detector to receive commands from a SONY DVD remote
irPulse VAR Word(4) '12 as noted in demo- only 4or5 are needed
irCounter VAR Nib '- i am out of ram
irMessage VAR Byte ' i sometimes get false numbers...
' -----[ Constants ]-------------------------------------------------------
ActiveHigh CON 1 ' Used to set PULSIN commands for IR
ActiveLow CON 0 ' to detect +/- pulses.

'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////
'THE PROGRAM
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////
Initialize:
'All pins are input at startup, PULSOUT takes care of flipping Output by itself
'The LOW command sets the specified pin to 0 (a 0 volt level)
' and then sets its mode to output.
' LOW6 is same as OUT6 = 0 DIR6 = 1
LOW RetractServo
LOW PositionerServo
LOW ArmServo
LOW BrakeServo
LOW DumperServo
'the photo resistor will be High 6 ONLY while running AFAIK
LOW CheckLight

DEBUG "Program started",CR 'Print to computer screen
DO 'Do a MAIN LOOP Responding to the 3 Buttons ...
'or the IR remote...
'Check Buttons at Start AND while Looping ...
'Flash some LEDs GreenLight PIN 9 , RedLight PIN 8
'this could be check- red- check- green- and save code space?
'this is GR GR GR GRR
'2 µs x 5000= 10 000 =10msec light ?? pause
'go check buttons rather than pause to 'seem' interactive
GOSUB Check_Buttons 'PAUSE 100
PULSOUT GreenLight,6500 ' ON Green LED
GOSUB Check_Buttons 'PAUSE 200 '200msec OFF
PULSOUT RedLight,5000 'red
GOSUB Check_Buttons 'PAUSE 100
PULSOUT GreenLight,6500 ' ON
GOSUB Check_Buttons 'PAUSE 200 '200msec OFF
PULSOUT RedLight,5000 'red
GOSUB Check_Buttons 'PAUSE 100
PULSOUT GreenLight,6500 ' ON Green LED
GOSUB Check_Buttons 'PAUSE 200 '200msec OFF
PULSOUT RedLight,5000 'red
GOSUB Check_Buttons 'PAUSE 100
PULSOUT GreenLight,6500 'four flashes ident this program version
GOSUB Check_Buttons 'PAUSE 200
PULSOUT RedLight,5000 'red
GOSUB Check_Buttons
PULSOUT RedLight,5000
'MAIN LOOP ENDS here
LOOP 'YES it will run Forever .. UNTIL IR Remote 0: END is pressed
END 'so this end is redundant and never used, wasting program space
'as long as the code is correct :)
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////
'The Program Ends
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////


'/////////////////////////////////////////////////////
'Check_Buttons:
'/////////////////////////////////////////////////////
Check_Buttons: '50
'time = 0 ' this is used and reused and gets trashed... so set+reset
FOR counter = 1 TO 10 'check a lot between the LEDs being ON
'Start and Run the Sequence .. StartDumpRun
IF (StartButton=1) THEN GOSUB Start_Dump_Run
'Emergency Stop OBE so changed to Position1CarBtn
IF (Position1CarBtn=1) THEN GOSUB Position_1Car
'Dumper
IF (RotateDumper1Btn=1) THEN GOSUB Rotate_Dumper
'IR TV control similar to 3 Buttons
'...except have 10 or more commands! BUT NO RESET btn - YET-
'Need a Pin available to send a LOW to Pin 22
'Catch 22 The End button on Box is not needed as there is a
'hardwired reset btn- But BOE Reset is NOT hardwired NOR very accessable
' Wait for IR detector output Use For 1 to 15 to check
FOR irCounter = 1 TO 15 'to go low. If detected then process
IF IRDetector = 0 THEN GOSUB Do_IR_Processing
NEXT
NEXT

RETURN 'return from a Gosub
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////
' More than 4 GOSUBS ...
'GOSUB Check_Buttons GOSUB Start_Dump_Run GOSUB Position_1Car -> Go subs
'GOSUB Do_IR_Processing
'Does it Crash or Reset to Program Start ... eheheehe

'Gosub_Reset:
' GOSUB Gosub_Reset
'RETURN 'this Crashes
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////
Do_IR_Processing:
FOR irCounter = 0 TO 15
PULSIN IRDetector,ActiveLow,irPulse(0)
IF irPulse(0) > 900 THEN EXIT ' Exit FOR...NEXT after start
'ENDIF ' pulse is detected.
NEXT 'counter 0 to 15

'... Process IR Pulses
DO
PULSIN IRDetector,ActiveHigh,irPulse(0)
LOOP UNTIL (irPulse(0) > 1400) AND (irPulse(0) <> 0)
PULSIN IRDetector,ActiveLow,irPulse(0)
PULSIN IRDetector,ActiveLow,irPulse(1)
PULSIN IRDetector,ActiveLow,irPulse(2)
PULSIN IRDetector,ActiveLow,irPulse(3)

FOR irCounter = 0 TO 3
IF (irPulse(irCounter) < 450) THEN
irMessage.LOWBIT(irCounter) = 0
ELSE
irMessage.LOWBIT(irCounter) = 1
ENDIF
NEXT

DEBUG "Binary Value: ", BIN8 irMessage, CR
DEBUG "Decimal Value: ", DEC4 irMessage, CR ' DEC DEC4

'changing to gosub rather than 8 debugs saved 2 words of code !
'but that was 24 characters , should be 12 words saved ?
'Since there is no screen when actually RUNNING DEBUG is useless then...
'Seems a shame and waste of code space
'DEBUG in Code Sections, then Comment out the Debug lines :)
'o but then its not as much fun to run the program eheheheh
SELECT irMessage 'these are Case xxx+1 : the 1 button sends a 000 etc...
'1 2 3
CASE 000 : GOSUB Start_Dump_Run'DEBUG "000"
CASE 001 : GOSUB Position_1Car 'DEBUG "001"
CASE 002 : GOSUB Rotate_Dumper 'DEBUG "002"
'4 5 6
CASE 003 : GOSUB Set_Brake'DEBUG "003"
CASE 004 : GOSUB Lower_Brake'DEBUG "004"
CASE 005 : GOSUB Lane_Open'DEBUG "005"
'7 8 9
CASE 006 : GOSUB Lane_Closed'DEBUG "006"
CASE 007 : GOSUB Hyperspaced'DEBUG "007"
CASE 008 : GOSUB Make_Music'DEBUG "008"
'0
CASE 009 : GOTO Initialize'END 'DEBUG "009"
CASE ELSE : GOSUB Hyperspaced 'DEBUG "Nada" 'Case else is catch all else
ENDSELECT 'sometimes the message gets scrambled and seems to stall
'- so the CASE ELSE gives it somewhere to go ..
'it should just go to line after ENDSELECT
'.. but well you know
'DEBUG CR 'this is from the debug
RETURN

'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////


'/////////////////////////////////////////////////////
'StartDumpRun Starts here
'/////////////////////////////////////////////////////
Start_Dump_Run :
DEBUG "Positioner started",CR
'Put 1 car ahead of Loop
'GOSUB LaneOpen 'moved into Position_1Car.. does a LOT more action there
'rather than 1 at start - 1 at end.. tho actually only times needed :)
GOSUB Position_1Car

'Check Light detector
GOSUB Traffic_Light
IF (noMoreCars=1) THEN GOTO Initialize
'END 'Something is Really wrong-or just testing
DEBUG "Lets dump this Unit Train!",CR
DEBUG "till the Light is less than the Shadow",CR
DO
DEBUG "Positioner started",CR
GOSUB Position_1Car

'Could maybe use a light detector at Edge of dumper to check for
'correct placement- but setting it up so no false reads seems Difficult-
'It would depend on where the light is from
' as the detector would be at edge of car.
'the one in middle of track underneath a car is prone to false reads...

DEBUG "Rotating Dumper",CR
GOSUB Rotate_Dumper


GOSUB Traffic_Light
IF (noMoreCars=1) THEN EXIT 'See Light at end of tunnel
LOOP

DEBUG "All done! use Locomotive for positioning",CR
DEBUG "Dumper Control with the Dumper button",CR
'Raise arm a LITTLE bit to release Coupler so Power can move the cars
FOR counter= 932 TO 789 STEP 10 'gradual raise arm a LITTLE bit
PULSOUT ArmServo, counter 'hope they dont roll away...
PAUSE 20 'o they cant-arm is on this side
NEXT 'Power is at the Front of train again
GOSUB Lower_Brake
'GOSUB LaneClosed 'moved into Position_1Car
GOSUB Hyperspaced 'If i knew music i would play a tune
GOSUB Make_Music 'or play a cellphone ringtone-er not enough ram
GOTO Initialize 'trick to avoid the fact
RETURN 'that it took too many GOSUBs to get here
'/////////////////////////////////////////////////////
'Start_Dump_Run ENDS here
'/////////////////////////////////////////////////////


'/////////////////////////////////////////////////////
' LaneClosed LaneOpen Swing the retract servo arm
'/////////////////////////////////////////////////////
' hitec retract servo 1430 : 715 is brake on ... 1440:720 is open
'Even though it is a retract servo - it only moves in the direction
'as LONG as there is a pulse given to it.
'other servos SNAP to a location.. if it is far away
Lane_Closed:
FOR counter= 0 TO 60
PULSOUT RetractServo, 500'715-counter 'Swing arm into train path
PAUSE 20 '750 is normal centered
NEXT
RETURN
'/////////////////////////////////////////////////////
Lane_Open:
FOR counter= 0 TO 60
PULSOUT RetractServo, 1000'820+counter '720 Swing arm clear of track
PAUSE 20
NEXT
RETURN
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////


'/////////////////////////////////////////////////////
'Hyperspaced: notification of completion
'/////////////////////////////////////////////////////
Hyperspaced: 'freq values ~4500-5000 play loudest
PAUSE 100 '? Octave 6+7 1046..4186
FOR duration = 15 TO 1 'STEP 1 Step 1 is Normal? change
FOR frequency = 3000 TO 4500 STEP 60 ' 2000 2500 20
FREQOUT Siren, duration, frequency
NEXT
NEXT
'FREQOUT PIN, Duration, Freq1 {, Freq2}
FREQOUT Siren, 2000, 4000, 4010 ' 2000 2010
RETURN
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////


'/////////////////////////////////////////////////////
'Traffic_Light:
'/////////////////////////////////////////////////////
' HIGH 6 is same as OUT6 = 1 and DIR6 = 1
' Make the specified pin an output and high.
'OUTx = 0:Low 0 Volt =1: High:5Volt
'DIRx = 0: Pin is an Input = 1: Pin is an Output
' The HIGH command sets the specified pin to 1 (a +5 volt level)
' and then sets its mode to output.
' LOW 6 OUT6 = 0 DIR6 = 1
' The LOW command sets the specified pin to 0 (a 0 volt level)
' and then sets its mode to output.
'/////////////////////////////////////////////////////
Traffic_Light:
HIGH CheckLight ' CheckLight PIN 6
PAUSE 100 'charge capacitor
RCTIME CheckLight, 1, time
IF (time < carShadow) THEN noMoreCars=1
'DEBUG HOME, "time = ", DEC5 time," CarShadow = ",DEC5 CarShadow
DEBUG "Light ", DEC5 time," < ",DEC5 carShadow, " Shadow?", CR
'>1600 is a car <50 is no car , carShadow = 500
' Dark is big, Light is small time values
LOW CheckLight ' i dunno if i should,
'but i dont want current charging all the time
RETURN
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////


'/////////////////////////////////////////////////////
'Position_1Car
'/////////////////////////////////////////////////////
'Brake should be Set, Arm Down
'Positioner ArmServo values
' 900 all UP, 1500 Car top, 1800 above coupler, 1830 grabs coupler
' 1840 ehh, 1850 ehehe, 1855 good little loose, 1860 ! little loose
' 1865 ok, 1870 tight, 1873 too Tight, 1880 Servo grumbling
'932=1864 1864=932=466
'/////////////////////////////////////////////////////
Position_1Car: 'Start at Gate, Move Back, Push Car Forward
'Check-Set brake just in case, Raise Arm, Move Positioner to Back,
PULSOUT BrakeServo, brakeSet
PAUSE 20
GOSUB Lane_Closed

'Raise arm SLOWLY ? to clear cars
FOR counter= 932 TO 466 STEP 10 '1864 to 932 gradually raise arm
PULSOUT ArmServo, counter
PAUSE 20
NEXT
PULSOUT ArmServo, 466 ' Arm UP 'dunno what step does to leftovers
PAUSE 20


FOR counter = 1 TO 5 'Move Positioner back past the switch
PULSOUT PositionerServo, positionerStop-positionerSpeed
PAUSE 20
NEXT
counter=5
DO 'Positioner - is CW is Reverse
counter=counter+1
PULSOUT PositionerServo, positionerStop-positionerSpeed
PAUSE 20
LOOP WHILE (PositionerBack=0) 'away from dumper
PULSOUT PositionerServo, positionerStop
PAUSE 20

DEBUG "Positioner Reverse: ", DEC counter, CR

'Lower Arm to Grab Coupler and push, Lower Brake so cars can move
FOR Counter= 466 TO 888 STEP 5'10 '932 to 1776 gradual Lower arm
PULSOUT ArmServo, Counter
PAUSE 20
NEXT
FOR Counter= 888 TO 932 'Very gradually Lower arm 1776 to 1864 Coupler bar
PULSOUT ArmServo, Counter
PAUSE 20
NEXT
PULSOUT ArmServo, 932 ' Arm grabbed coupler
PAUSE 20

GOSUB Lower_Brake 'so cars can move forward

GOSUB Lane_Open
'Move Positioner forward, Set Brake
'12 :Positioner + is CCW is Forward
FOR counter = 1 TO 5 'Move it past the switch
PULSOUT PositionerServo, positionerStop+positionerSpeed
PAUSE 20
NEXT
counter=5
DO
counter=counter+1
PULSOUT PositionerServo, positionerStop+positionerSpeed
PAUSE 20
LOOP WHILE (PositionerAtEnd=0) 'PositionerAtEnd
PULSOUT PositionerServo, positionerStop
PAUSE 20

DEBUG "Positioner Forward: ", DEC counter, CR

GOSUB Lane_Closed
GOSUB Set_Brake
RETURN
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////


'/////////////////////////////////////////////////////
'Set_Brake:
'/////////////////////////////////////////////////////
Set_Brake:
'debug "Set Brake" 'commented out to reduce code size :(
FOR Counter= 750 TO brakeSet STEP 4 '10 gradual brake-raise arm to axle
PULSOUT BrakeServo, Counter '14 : Brake
PAUSE 20
NEXT
PULSOUT BrakeServo, brakeSet 'dunno what step does to leftovers
PAUSE 20
DEBUG "Brake Set" 'this and other used 6 bytes of code
RETURN ' from Sub SetBrake:

Lower_Brake:
'debug "Lower Brake"
FOR counter=brakeSet TO 750 STEP 10 'gradual release -- going down
PULSOUT BrakeServo, counter '14 : Brake
PAUSE 20
NEXT
PULSOUT BrakeServo, 750
PAUSE 20
DEBUG "Brake Lowered"
RETURN ' from Sub LowerBrake:
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////


'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////
'RotateDumper
'/////////////////////////////////////////////////////
'Set Dumper to rotating (its Not a Position, it is the rotation Speed
'Check Switch-Sensor and Reverse when it is hit
'till it is hit again at top and Stopped
'changed from variables when room ran out
' dumperSpeed VAR Byte
' dumperSpeed=20 'Set here to change all places easier
' dumperStop VAR Word
' dumperStop=760 'center of dead band

Rotate_Dumper: '15 : Dumper
DEBUG "Dumper started", CR

FOR counter = 1 TO 5 'Move it past the switch - then keep going
PULSOUT DumperServo, 780 '760 + is CCW is Forward to Dump
PAUSE 20
'DEBUG "Dumper ",DEC DumperSensor ,CR 'used during actual de-bugging once
NEXT
counter=5
'The servo IS turning till Switch hit
DO 'DO:LOOP WHILE(?=0) is a trick
counter=counter+1
PULSOUT DumperServo, 780 '760 + is CCW is Forward to Dump
PAUSE 20
LOOP WHILE (DumperSensor=0)
PULSOUT DumperServo, 760 'Stop turning, so it does not spit gears reversing
PAUSE 20

DEBUG "Dumper Upsidedown: ", DEC counter, CR

DEBUG "Dumper returning", CR

FOR counter = 1 TO 5 'Move it past the switch
PULSOUT DumperServo, 740 '760 - is CW is Reverse to TOP
PAUSE 20
NEXT
counter=5
'The servo IS turning till Switch hit
DO
counter=counter+1
PULSOUT DumperServo, 740 '760 - is CW is Reverse to TOP
PAUSE 20
LOOP WHILE (DumperSensor=0)
PULSOUT DumperServo, 760 'Stop turning, we are at top again
PAUSE 20

DEBUG "Dumper Topside: ", DEC counter, CR 'to count turnaround loops
DEBUG "Dumper Done", CR 'totally useless but interesting
RETURN
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////


'/////////////////////////////////////////////////////
'x VAR Bit ' Value can be 0 or 1
'y VAR Nib ' Value can be 0 to 15
'z VAR Byte ' Value can be 0 to 255
'zz VAR Word ' Value can be 0 to 65535
'/////////////////////////////////////////////////////
Make_Music: 'Music data is at TOP of program
' MMindex VAR Byte 'could use counter here too... uhm well NO
'counter 'time
'irCounter 'offset VAR Nib
' noteLetter VAR Byte 'irMessage got clobbered too much to use
'frequency 'noteFreq VAR Word
'duration 'noteDuration VAR Word
'MMindex VAR Nib
noteLetter = "a" 'If run again.. it is still a Q
time = 0 ' this is used and reused and gets trashed... so set+reset
irCounter=0
DO UNTIL noteLetter = "Q"
READ Notes + time, noteLetter
LOOKDOWN noteLetter, [ "A", "b", "B", "C", "d",
"D", "e", "E", "F", "g",
"G", "a", "P", "Q" ], irCounter
LOOKUP irCounter, [ 1760, 1865, 1976, 2093, 2217,
2349, 2489, 2637, 2794, 2960,
3136, 3322, 0, 0 ], frequency
READ Durations + time, duration
duration = WholeNote / duration
FREQOUT Siren, duration, frequency
time = time + 1
LOOP
RETURN
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////



'/////////////////////////////////////////////////////
'NO MORE CODE :)
'/////////////////////////////////////////////////////
END 'just in double case, yes some more wasted code space :)

Code for BS2 BOE

' {$STAMP BS2}
' {$PBASIC 2.5}
' Dump4everV3.bs2 as of 2009dec14
' Written for an Education Board: 4 Servos are hard wired to pins 12-15
' V1 started in 2009November
' V2 Changed Positioner code to try to get the push bar to place car OVER brake
' V3 Changed Pusher bar to a Coupler Grabber

' Controls four servos of an automated HO scale rotary dumper
' 1. Dumper motor is a Parallax Futaba limitless servo.
' It has a PULSOUT dead band (758..761 x2usec) 1515..1522.
' Values near the deadband control the speed that reachs a maximum
' of about 60RPM at PULSOUT values of about +/-40. 1 RevPerSecond.
' The travel limits are controlled with a single flapper switch
' flapped at 2 positions Reverse and StopatTop
' 2. Positioner motor is a Parallax Futaba limitless servo.
' It has a PULSOUT dead band (756 TO 760 x2usec) 1512 to 1520 .
' 'ditto' has 2 flapper switches :PositionerAtEnd and PositionerBack
' 3. Positioner Arm motor is a Parallax Futaba servo.
' It rides on the Positioner cart and raises - lowers its arm
' to be the positioner car coupler grabber
' 4. Brake is an old Futaba servo.
' It is under the track and raises its arm
' to hold the car in the correct position.

' The red green LEDs will be flashing when system is powered up
' and a reset cycle has been done. It will flash idiot lights
' when the system is waiting for a train

'After Initialization-Power on - the cars are placed in position
' Three Buttons on a Servo extension in a bashed Coalgon
StartButton PIN 0 'white-yel wire
'Just in case
EmergencyStopBtn PIN 1 'red wire
'Used when done to dump last car(s) pulled onto dumper by other loco
RotateDumper1Btn PIN 2 'black wire

'Flapper switches for servo movement limits
'Positioner limits
PositionerAtEnd PIN 3 'black wire Positioner Near Dumper
'A B hehehe - this will haunt me right ?
PositionerBack PIN 4 'red wire Positioner at back
'1 switch-sensor used to Reverse and Stop at Top Dumper
DumperSensor PIN 5 ' white wire
'Photo diode light detector
CheckLight PIN 6 'its own wire set
'not really coded - just flashing lights
GreenLight PIN 7 'yel-white wire
'No error detection AFAIK so just for funsies
RedLight PIN 8 'red wire , black of set is ground
Siren PIN 9 'on board only- sounds at end of cycle
'IR detector for a hand held TV remote control IAW Three Buttons
'PIN 10
'o what to do with these, i just gotta use it all :)
'Additional Servo Positioner Retract servo-
'but not needed if the Positioner actually Works ...
'used to Stop the incoming train cars at correct location
'PIN 11

'4 Servos on Pins: 12 :Positioner, 13: Arm, 14 : Brake, 15 : Dumper
dumperSpeed VAR Word
dumperSpeed=20 'Set here to change all places easier
dumperStop VAR Word
dumperStop=760 'center of dead band
positionerSpeed VAR Word
positionerSpeed=20 'Set here to change all places easier
positionerStop VAR Word
positionerStop=758 'center of dead band
brakeSet VAR Word
brakeSet=570 '582 '583 'Brake holds the axle Tight

'THE PLOT
'A Unit train arrives and the Power de-couples from front
' and runs around dumper to wait for its train to be dumped.
' The train is Pushed to Positioner by Industry Power.
'The Positioner is near dumper, Arm and the Brake are Down.
'the Start Button is Pressed
'Position1Car: Push 1 car forward and Brake it,
'Check if more cars (Light detector) {it is needed here the first time...}
'then go into the lOOP
'lOOP:
'Push 1 car forward and Brake it, the car before is Now in dumper
'Rotate Dumper
'Check if more cars (Light detector )
'Repeat LOOP until Detector Exits the Loop : no more cars
'Done: Retract brake and raise Positioner a LITTLE bit
' as it has GRABBED the Coupler
' Positioner Near Dumper and the Arm raised a LITTLE
'Thus at end 1 car on ready-track , 1 car On dumper : IS dumped
'Pull Last car through-onto Dumper from other end with Power locomotive.
' Then Dump Last car Using the 3rd Push button to activate Dumper

'global variables Byte : Value can be 0 to 255
counter VAR Word ' Value can be 0 to 65535
debugthis VAR Word
carShadow VAR Word
' >1600 is a car <50 is no car , THIS is middle low
carShadow=500
time VAR Word 'IF (time < CarShadow) THEN NoMoreCars=1
noMoreCars VAR Bit
duration VAR Word 'for Sound
frequency VAR Word 'ditto

'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////
'THE PROGRAM
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////
DEBUG "Program started",CR 'Print to computer screen
DO 'Do a MAIN LOOP Responding to the 3 Buttons ...
'Initialize Something
'All pins are input at startup, PULSOUT takes care of Output by itself
'the photo resistor will be High 6 ONLY while running AFAIK

'Check Buttons at Start AND while Looping ...
GOSUB Check_Buttons

'Flash some LEDs GreenLight PIN 8 , RedLight PIN 9
PULSOUT 8,50000 'red
'go check buttons rather than pause to 'seem' interactive
GOSUB Check_Buttons 'PAUSE 100
PULSOUT 7,65000 '130msec ON Green LED
GOSUB Check_Buttons 'PAUSE 200 '200msec OFF
GOSUB Check_Buttons
PULSOUT 8,50000 'red
GOSUB Check_Buttons 'PAUSE 100
PULSOUT 7,65000 '130msec ON
GOSUB Check_Buttons 'PAUSE 200 '200msec OFF
GOSUB Check_Buttons
PULSOUT 8,50000 'red
GOSUB Check_Buttons 'PAUSE 100
PULSOUT 7,65000 '130msec ON Green LED
GOSUB Check_Buttons 'PAUSE 200 '200msec OFF
GOSUB Check_Buttons
PULSOUT 8,50000 'red
GOSUB Check_Buttons 'PAUSE 100
PULSOUT 7,65000 'four flashes ident this program version
GOSUB Check_Buttons 'PAUSE 200
GOSUB Check_Buttons
PULSOUT 8,50000 'red
GOSUB Check_Buttons 'PAUSE 100
'MAIN LOOP ENDS here
LOOP 'YES it will run Forever .. UNTIL Emergency STOP BUTTON is pressed
END 'so this end is redundant and never used, wasting program space
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////
'The Program Ends
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////

'/////////////////////////////////////////////////////
'Check_Buttons:
'/////////////////////////////////////////////////////
Check_Buttons:
FOR counter = 1 TO 50 'check a lot between the LEDs being ON
'Start and Run the Sequence .. StartDumpRun
IF (StartButton=1) THEN GOSUB Start_Dump_Run
'Emergency Stop
IF (EmergencyStopBtn=1) THEN END
'Dumper
IF (RotateDumper1Btn=1) THEN GOSUB Rotate_Dumper
NEXT
'IR TV control would be similar to 3 Buttons ... someday
RETURN 'return from a Gosub
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////


'/////////////////////////////////////////////////////
'StartDumpRun Starts here
'/////////////////////////////////////////////////////
Start_Dump_Run :
DEBUG "Positioner started",CR
'Put 1 car ahead of Loop
GOSUB Position_1Car
IF (emergencyStopBtn=1) THEN END

'Check Light detector
GOSUB Traffic_Light
IF (noMoreCars=1) THEN END 'Something is Really wrong-or just testing
DEBUG "Lets dump this Unit Train!",CR
DEBUG "till the Light is less than the Shadow",CR
DO
'BE SURE TO Watch for the Emergency Stop Button! During the Sequence
IF (emergencyStopBtn=1) THEN END

DEBUG "Positioner started",CR
GOSUB Position_1Car
IF (emergencyStopBtn=1) THEN END

'Could maybe use a light detector at Edge of dumper to check for
'correct placement- but setting it up so no false reads seems Difficult-
'It would depend on where the light is from
' as the detector would be at edge of car.

DEBUG "Rotating Dumper",CR
GOSUB Rotate_Dumper
IF (emergencyStopBtn=1) THEN END

GOSUB Traffic_Light
IF (noMoreCars=1) THEN EXIT 'See Light at end of tunnel
LOOP

DEBUG "All done! use Locomotive for positioning",CR
DEBUG "Dumper Control with the Dumper button",CR
'Raise arm a LITTLE bit to release Coupler so Power can move the cars
FOR counter= 932 TO 789 STEP 10 'gradual raise arm a LITTLE bit
PULSOUT 13, counter 'hope they dont roll away...
PAUSE 20 'o they cant-arm is on this side
NEXT 'Power is at the Front of train again
GOSUB Lower_Brake
GOSUB Hyperspaced 'If i knew music i would play a tune
RETURN 'or cared to play a cellphone ringtone
'/////////////////////////////////////////////////////
'Start_Dump_Run ENDS here
'/////////////////////////////////////////////////////

'/////////////////////////////////////////////////////
'Hyperspaced: notification of completion
'/////////////////////////////////////////////////////
Hyperspaced:
PAUSE 100
FOR duration = 15 TO 1 'STEP 1 Step 1 is Normal? change
FOR frequency = 2000 TO 2500 STEP 20
FREQOUT 9, duration, frequency
NEXT
NEXT
FREQOUT 9, 2000, 2000, 2010
RETURN
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////


'/////////////////////////////////////////////////////
'Traffic_Light:
'/////////////////////////////////////////////////////
' HIGH 6 is same as OUT6 = 1 and DIR6 = 1
' Make the specified pin an output and high.
' The HIGH command sets the specified pin to 1 (a +5 volt level)
' and then sets its mode to output.
' LOW 6 OUT6 = 0 DIR6 = 1
' The LOW command sets the specified pin to 0 (a 0 volt level)
' and then sets its mode to output.
'/////////////////////////////////////////////////////
Traffic_Light:
HIGH 6 ' CheckLight PIN 6
PAUSE 100 'charge capacitor
RCTIME 6, 1, time
IF (time < carShadow) THEN noMoreCars=1
'DEBUG HOME, "time = ", DEC5 time," CarShadow = ",DEC5 CarShadow
DEBUG "Light ", DEC5 time," < ",DEC5 carShadow, " Shadow?", CR
'carShadow = 500 '>1600 is a car <50 is no car
'Dark is big, Light is small time values
LOW 6 ' i dunno if i should,
'but i dont want current charging all the time
RETURN
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////


'/////////////////////////////////////////////////////
'Position_1Car
'/////////////////////////////////////////////////////
'Brake should be Set, Arm Down
'Positioner Arm values
' 900 all UP, 1500 Car top, 1800 above coupler, 1830 grabs coupler
' 1840 ehh, 1850 ehehe, 1855 good little loose, 1860 ! little loose
' 1865 ok, 1870 tight, 1873 too Tight, 1880 Servo grumbling
'932=1864 1864=932=466
'/////////////////////////////////////////////////////
Position_1Car:
'Check-Set brake just in case, Raise Arm, Move Positioner to Back,
PULSOUT 14, brakeSet
PAUSE 20

'Raise arm SLOWLY ? to clear cars
FOR counter= 932 TO 466 STEP 10 'gradual raise arm
PULSOUT 13, counter
PAUSE 20
NEXT
PULSOUT 13, 466 '13: Arm 'dunno what step does to leftovers
PAUSE 20
'DIR13=0 'remove pulse to insure stop
IF (emergencyStopBtn=1) THEN END

FOR counter = 1 TO 5 'Move it back past the switch
PULSOUT 12, positionerStop-positionerSpeed
PAUSE 20
NEXT
debugthis=0 '12 :Positioner - is CW is Reverse
DO
debugthis=debugthis+1
PULSOUT 12, positionerStop-positionerSpeed
PAUSE 20
LOOP WHILE (PositionerBack=0) 'away from dumper
PULSOUT 12, positionerStop
PAUSE 20
'DIR12=0 'remove pulse to insure stop
DEBUG "Positioner Reverse: ", DEC debugthis, CR
IF (EmergencyStopBtn=1) THEN END

'Lower Arm to Grab Coupler and push, Lower Brake so cars can move
FOR Counter= 466 TO 888 STEP 5'10 'gradual Lower arm
PULSOUT 13, Counter
PAUSE 20
NEXT
FOR Counter= 888 TO 932 'Very gradually Lower arm to Coupler bar
PULSOUT 13, Counter
PAUSE 20
NEXT
PULSOUT 13, 932 '13: Arm
PAUSE 20
' DIR13=0 'remove pulse to insure stop
IF (emergencyStopBtn=1) THEN END

GOSUB Lower_Brake 'so cars can move forward
IF (emergencyStopBtn=1) THEN END

'Move Positioner forward, Set Brake
debugthis=0 '12 :Positioner + is CCW is Forward
FOR counter = 1 TO 5 'Move it past the switch
PULSOUT 12, positionerStop+positionerSpeed
PAUSE 20
NEXT
DO
debugthis=debugthis+1
PULSOUT 12, positionerStop+positionerSpeed
PAUSE 20
LOOP WHILE (PositionerAtEnd=0) 'PositionerAtEnd
PULSOUT 12, positionerStop
PAUSE 20
' DIR12=0 'remove pulse to insure stop
DEBUG "Positioner Forward: ", DEC debugthis, CR
IF (EmergencyStopBtn=1) THEN END

GOSUB Set_Brake
RETURN
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////


'/////////////////////////////////////////////////////
'Set_Brake:
'/////////////////////////////////////////////////////
'Brake ups and downs
'1000 is Topped OUT : 500 : it hits the track above
'1050 is just clear of Top Out : 525
'1130 '1161 it Lifts the wheels from the track 580 or 581 582
'1136 ...1140 is Good and Tight
'1140 : 570 '1164 : brakeSet=582
'1145 '1166 BrakeSet is just before : 583
'1150 ...is caught but...
'1200 is caught but way loose 600
'1500 is Below track : 750 normal centered
'1800 is bottom out:900
'/////////////////////////////////////////////////////
Set_Brake:
'debug "Set Brake"
FOR Counter= 750 TO brakeSet STEP 4 '10 gradual brake-raise arm to axle
PULSOUT 14, Counter '14 : Brake
PAUSE 20
NEXT
PULSOUT 14, brakeSet 'dunno what step does to leftovers
PAUSE 20
' DIR14=0 'remove pulse to insure stop
'debug "Brake Set"
RETURN ' from Sub SetBrake:

Lower_Brake:
'debug "Lower Brake"
FOR counter=brakeSet TO 750 STEP 10 'gradual release -- going down
PULSOUT 14, counter '14 : Brake
PAUSE 20
NEXT
PULSOUT 14, 750
PAUSE 20
' DIR14=0 'remove pulse to insure stop
'debug "Brake Lowered"
RETURN ' from Sub LowerBrake:
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////


'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////
'RotateDumper
'/////////////////////////////////////////////////////
'Set Dumper to rotating (its Not a Position, it is the rotation Speed
'Check Switch-Sensor and Reverse when it is hit
'till it is hit again at top and Stopped

Rotate_Dumper: '15 : Dumper
DEBUG "Dumper started", CR
debugthis=5
FOR counter = 1 TO 5 'Move it past the switch - then keep going
PULSOUT 15, dumperStop+dumperSpeed ' + is CCW is Forward to Dump
PAUSE 20
'DEBUG "Dumper ",DEC DumperSensor ,CR 'used during actual de-bugging once
NEXT

'The servo IS turning till Switch hit
DO 'DO:LOOP WHILE(?=0) is a trick
debugthis=debugthis+1
PULSOUT 15, dumperStop+dumperSpeed ' + is CCW is Forward to Dump
PAUSE 20
LOOP WHILE (DumperSensor=0)
PULSOUT 15, dumperStop 'Stop turning, so it does not spit gears reversing
PAUSE 20
IF (emergencyStopBtn=1) THEN END
DEBUG "Dumper Upsidedown: ", DEC debugthis, CR

DEBUG "Dumper returning", CR
debugthis=5
FOR counter = 1 TO 5 'Move it past the switch
PULSOUT 15, dumperStop-dumperSpeed ' - is CW is Reverse to TOP
PAUSE 20
NEXT

'The servo IS turning till Switch hit
DO
debugthis=debugthis+1
PULSOUT 15, dumperStop-dumperSpeed ' - is CW is Reverse to TOP
PAUSE 20
LOOP WHILE (DumperSensor=0)
PULSOUT 15, dumperStop 'Stop turning, we are at top again
PAUSE 20
' DIR15=0 'remove pulse to insure stop
IF (emergencyStopBtn=1) THEN END
DEBUG "Dumper Topside: ", DEC debugthis, CR 'to count turnaround loops
DEBUG "Dumper Done", CR 'totally useless but interesting
RETURN
'/////////////////////////////////////////////////////
'/////////////////////////////////////////////////////


'/////////////////////////////////////////////////////
'NO MORE CODE :)
'/////////////////////////////////////////////////////
END 'just in double case, yes some more wasted code space :)

Monday, January 4, 2010

EOL

The rotary dumper is completed -as far as i am concerned- except for landscaping and moving the controller underneath the board in front of the rotary dumper. One of the first images has it where it will go. The only problem is that the cars fall off the track when they are turned upside down - the springs are not strong enough to hold them :( i made rails along the track to help keep them aligned... but they still derail and uncouple sometimes...

The controller code and information is posted at Parallax in the completed projects forum.

Now working on a controller for the Rocket tubes - rather than the remote control radio it is now dis-connected from. Actually it is basically finished- just hook up servo wires to the controller - the code was simple enough- use the IR remote and raise-lower the tubes on command. Just thinking about having rotating 'radar' dishes, other sounds when someone approaches, etc... but that is all sprinkles on the whipped cream on the dessert... The RC had glitches.. the great thing about these controllers is the LACK of glitches.. i ran a train underneath the dumper and it had no glitches... actually the RC only- well mainly- glitched when it was perpendicular to the radio antennae. OOpso, the controller will not fit in the cars... will have to cut apart or make my own board... one that is about 1" wide and thus about 6" long, rather than the standard ~3"x3"...

eol