|
Forum Index : Microcontroller and PC projects : PicoRR: Vibe Virtual Model Railroad
| Author | Message | ||||
| lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3660 |
Vibe Virtual Model Railroading I wanted an application to exercise and test PicoDB . About 8 weeks ago, someone mentioned an interest in model railroad control. After I finished PicoDB, I thought that might be just the ticket. I had an HO gauge layout when I was a teenager, but have hardly given a thought to it in 60 years. I started work on it with Gemini on February 14. The exercise has been a success--the virtual model train works, and PicoDB serves it (and we found and fixed 4 obscure bugs in PicoDB). The program, PicoRR.bas, is 2058 lines long. The PicoDB library is 2545 lines. That's 4600+ lines of MMBasic code from Gemini since January 13--50 days, 92 lines a day (but with 2 sets of guests visiting and a porch built on our shed which subtracted about 10 days total). Here's a youtube video of 4 trains running. The frame rate is only 1-2 frames per second, but if this were translated to an 8-foot by 6-foot layout, the speeds would be pretty much in range: PicoRR Demo (doesn't hurt to run it an 1.5 speed). Here's the script which drove the video: s10+ve3 4,delay 3,ve3 0s10-ve3 -3 delay 3,ce3s9+s8+s4+ve3 25 at e3 inner-e,s8-s9-s4- at e3 inner-w,s16+s14+s13+ s6+s3+ve1 35,at e3 Mainline-E,s16- s14-s15+s11+,ve1 45 at e1 Mainline-W,s6-s3-s15-s11-s13- s7+s3+,ve2 20 at e1 Mainline-N, delay 2 s12+ at e3 Mainline-W,s17+s7-s8+ delay 4,ve4 7,delay 15,s8- ve3 35,s17+ at e1 Mainline-S, delay 3,s17-s18+ at e2 Inner-W, s4+s2+s1+s3+s7-ve4 20 s12-s13+ve3 25, ve1 25 at e1 Mainline-N,delay 3, s13-s12+ s17+ve3 35,ve1 35 at e3 Mainline-W,S18- at e1 Mainline-S,ve1 2,ve3 2 delay 5,s17-s18+ve1 25, ve3 25 s13+s12- Loop 16 This is running on Peter's Pico2 HDMI PCB: ![]() You drive the trains by typing commands (on PC/laptop keyboard--I don't have a keyboard attached to the PCB) at the "DISPATCH>" prompt on the Screen/LCD. For instance, s6+ve1 20 will flip switch 6 out of spur2 and start up the train behind Engine E1. Here's the quick help ("?" at the "DISPATCH>" prompt) for dispatch commands at the keyboard. ======================================================================= MODEL RAILROAD OS - HELP MENU ======================================================================= --- DISPATCH COMMANDS --- Commands can be chained together using commas (e.g., S1+, VE1 10, CE3) Switch commands can be auto-chained (e.g., S5+S3+S4-) V[E#] [speed] : Set velocity. Positive=Forward, Negative=Reverse. Use + or - to increment/decrement from current speed. Ex: VE1 15 (Moves Engine 1 forward at speed 15) Ex: VE1 -5 (Slows Engine 1 down by 5) Ex: V0 (GLOBAL EMERGENCY STOP. Halts all trains) S[#][+/-] : Throw switch # to Diverging (+) or Straight (-). Ex: S5+ (Throws switch 5) Ex: S5+S3- (Throws 5 diverging, 3 straight) U[E#] [qty] : Uncouple [qty] cars from Engine # and drop them on the current track segment. If [qty] is omitted, drops ALL. Ex: UE4 2 (Drops the last 2 cars from E4's consist) Ex: UE4 (Drops all cars, leaving only the engine) C[E#] [qty] : Couple Engine # to cars parked on its current track. Ex: CE3 1 (Couples exactly 1 car to E3) Ex: CE3 (Couples ALL cars on the track to E3) A[Loc][R/L][E#] : Fast-Assemble a consist at [Loc] facing [R]ight or [L ]eft. Ex: ASpur1RE3B1 (Puts E3 and B1 on Spur1 facing Right) RR : Rotate the Roundhouse turntable 180 degrees. H, ?, !H : Display this help menu. --- SCRIPTING COMMANDS --- (Used inside .scr files, or processed via the pre-processor) DELAY [sec] : Pauses the script for [sec] seconds. Ex: DELAY 5 AT [E#] [Loc] : Pauses script until Engine # enters [Loc] (SegID or Friendly). Ex: AT E3 Spur1 LOOP [n] : Jumps script execution back to line [n] (default 1). Ex: LOOP 8 --- META / SYSTEM COMMANDS --- !! : PAUSE / RESUME. Instantly freezes/unfreezes physics and scripts. !RECORD [name] : Begins buffering live commands to a .scr file. Ex: !RECORD myrun.scr !STOP : Stops recording and saves the buffer to the file. !PLAY [name] : Compiles and executes a script file. Ex: !PLAY myrun.scr !SNAP [name] : Save a screenshot to the SD card. Defaults to l.bmp. Ex: !SNAP yard.bmp !LAYOUT [#] : Hot-swap the track geometry to Layout #. Ex: !LAYOUT 3 !SHOW [C/F] : Toggle overlay labels on the layout. Ex: !SHOW F (Toggles Friendly Names) Ex: !SHOW C (Toggles Car IDs) !TEST [Code] : Executes raw MMBasic code or internal diagnostics. Ex: !TEST EXECUTE Print V(1) ======================================================================= There are 3 layouts available at present: ![]() Fuller documentation is in the zip file, which contains everything needed to run on a Pico2 HDMI, 640x480 Mode 3. I think it will work with VGA, but haven't located the boards I know I have somewhere. I have it displaying, but not yet running, on LCD 320x240 and 480x320. The library (which contains the PicoDB database engine) needs to be saved with LIBRARY SAVE. There are two driving files: roster.csv (which defines engines and cars), and segments.csv (defines track segments and switches): Roster: CarID,CarType,PixLen,ColorCode,Location,Sequence,Layout E1,Modern Eng,20,8,Spur2,1,* P1,Passenger,24,3,Spur2,2,* P2,Passenger,24,3,Spur2,3,* P3,Passenger,24,3,Spur2,4,* P4,Passenger,24,3,Spur2,5,* E2,30s Engine,16,12,Spur3,1,* C1,Centerbeam,22,7,Spur3,2,* R1,Reefer,16,5,Spur3,3,* G1,Gondola,16,2,Spur3,4,* H1,Hopper,14,4,Spur3,5,* T1,Tank Car,15,15,Spur3,6,* B1,Boxcar,16,10,Spur3,7,* E3,Yard Eng,10,9,Spur6,1,* E4,Modern Eng,20,8,Spur4,1,3 B2,Boxcar,16,10,Spur4,2,3 B3,Boxcar,16,10,Spur4,3,3 T2,Tank Car,15,15,Spur5,101,3 B4,Boxcar,16,10,Spur5,102,3 Segments: LayoutID,SegID,Type,Len,X1,Y1,X2,Y2,Radius,Next1,Next2,Next3,Friendly 1 ,L3,S,60.00,20.00,0.00,80.00,0.00,0.00,2,3,, 1 ,L2a,C,31.42,80.00,20.00,270.00,360.00,20.00,3,L2b,, 1 ,L2b,S,35.00,100.00,20.00,100.00,55.00,0.00,L2a,L2c,, 1 ,L2c,C,31.42,80.00,55.00,0.00,90.00,20.00,L2b,4,, 1 ,L1,S,60.00,80.00,75.00,20.00,75.00,0.00,4,1,, 1 ,L4a,C,31.42,20.00,55.00,90.00,180.00,20.00,1,L4b,, 1 ,L4b,S,35.00,0.00,55.00,0.00,20.00,0.00,L4a,L4c,, 1 ,L4c,C,31.42,20.00,20.00,180.00,270.00,20.00,L4b,2,, 1 ,Diag1a,S,57.60,80.00,0.00,44.00,45.00,0.00,3,7,, 1 ,Diag1b,S,9.60,44.00,45.00,38.00,52.50,0.00,7,6,, 1 ,Diag1c,S,9.60,38.00,52.50,32.00,60.00,0.00,6,5,, 1 ,Diag1d,S,19.20,32.00,60.00,20.00,75.00,0.00,5,1,, 1 ,Diag2a,S,38.40,20.00,0.00,44.00,30.00,0.00,2,8,, 1 ,Diag2b,S,57.60,44.00,30.00,80.00,75.00,0.00,8,4,, 1 ,Spur1,S,37.50,6.00,45.00,43.50,45.00,0.00,,7,,spur3 1 ,L10,S,31.50,6.00,52.50,37.50,52.50,0.00,,6,,spur2 1 ,L9,S,25.50,6.00,60.00,31.50,60.00,0.00,,5,,spur1 1 ,L12b,S,25.50,6.00,30.00,31.50,30.00,0.00,,9,,spur4 1 ,L12,S,11.50,32.00,30.00,43.50,30.00,0.00,9,8,, 1 ,Lad1,S,9.60,26.00,22.50,32.00,30.00,0.00,L13,9,, 1 ,L13b,S,13.50,6.00,22.50,19.50,22.50,0.00,,10,,spur5 1 ,L13,S,6.00,20.00,22.50,26.00,22.50,0.00,10,Lad1,, 1 ,Lad2,S,5.50,14.00,15.00,19.50,22.50,0.00,Roundhouse,10,,spur6 1 ,Roundhouse,S,8.00,6.00,15.00,14.00,15.00,0.00,,Lad2,, 1 ,1,SW,0.00,20.00,75.00,0.00,0.00,0.00,L4a,L1,Diag1d, 1 ,2,SW,0.00,20.00,0.00,0.00,0.00,0.00,L4c,L3,Diag2a, 1 ,3,SW,0.00,80.00,0.00,0.00,0.00,0.00,L2a,L3,Diag1a, 1 ,4,SW,0.00,80.00,75.00,0.00,0.00,0.00,L2c,L1,Diag2b, 1 ,7,SW,0.00,44.00,45.00,0.00,0.00,0.00,Diag1a,Diag1b,Spur1, 1 ,6,SW,0.00,38.00,52.50,0.00,0.00,0.00,Diag1b,Diag1c,L10, 1 ,5,SW,0.00,32.00,60.00,0.00,0.00,0.00,Diag1c,Diag1d,L9, 1 ,8,SW,0.00,44.00,30.00,0.00,0.00,0.00,Diag2b,Diag2a,L12, 1 ,9,SW,0.00,32.00,30.00,0.00,0.00,0.00,L12,L12b,Lad1, 1 ,10,SW,0.00,20.00,22.50,0.00,0.00,0.00,L13,L13b,Lad2, 1 ,X1,X,0.00,50.00,37.50,0.00,0.00,0.00,,,, 2 ,L2a_Ext,C,47.12,80.00,20.00,225.00,360.00,20.00,Diag1_C_S2,L2b,, 2 ,L2b,S,35.00,100.00,20.00,100.00,55.00,0.00,L2a_Ext,L2c_Ext,, 2 ,L2c_Ext,C,47.12,80.00,55.00,0.00,135.00,20.00,L2b,Diag2_S3_C,, 2 ,L4c_Ext,C,47.12,20.00,20.00,315.00,180.00,20.00,Diag2_S8_S4,L4b,, 2 ,L4b,S,35.00,0.00,20.00,0.00,55.00,0.00,L4c_Ext,L4a_Ext,, 2 ,L4a_Ext,C,47.12,20.00,55.00,180.00,45.00,20.00,L4b,Diag1_S1_S7,, 2 ,Diag1_S1_S7,S,10.22,34.14,69.14,38.72,60.00,0.00,L4a_Ext,5,, 2 ,Diag1_S7_S6,S,8.39,38.72,60.00,42.48,52.50,0.00,5,6,, 2 ,Diag1_S6_S5,S,8.39,42.48,52.50,46.24,45.00,0.00,6,7,, 2 ,Diag1_S5_C,S,8.39,46.24,45.00,50.00,37.50,0.00,7,Diag1_C_S2,, 2 ,Diag1_C_S2,S,22.42,50.00,37.50,65.86,5.86,0.00,Diag1_S5_C,L2a_Ext,, 2 ,Diag2_S3_C,S,22.42,65.86,69.14,50.00,37.50,0.00,L2c_Ext,Diag2_C_S8,, 2 ,Diag2_C_S8,S,8.39,50.00,37.50,46.24,30.00,0.00,Diag2_S3_C,8,, 2 ,Diag2_S8_S4,S,26.98,46.24,30.00,34.14,5.86,0.00,8,L4c_Ext,, 2 ,Spur1,S,39.74,6.00,45.00,45.74,45.00,0.00,,7,,spur3 2 ,L10,S,35.98,6.00,52.50,41.98,52.50,0.00,,6,,spur2 2 ,L9,S,32.22,6.00,60.00,38.22,60.00,0.00,,5,,spur1 2 ,L12,S,13.74,32.00,30.00,45.74,30.00,0.00,9,8,, 2 ,L12b,S,25.50,6.00,30.00,31.50,30.00,0.00,,9,,spur4 2 ,Lad1,S,9.60,26.00,22.50,32.00,30.00,0.00,L13,9,, 2 ,L13,S,6.00,20.00,22.50,26.00,22.50,0.00,10,Lad1,, 2 ,L13b,S,13.50,6.00,22.50,19.50,22.50,0.00,,10,,spur5 2 ,Lad2,S,9.60,14.00,15.00,20.00,22.50,0.00,Roundhouse,10,,spur6 2 ,Roundhouse,S,8.00,6.00,15.00,14.00,15.00,0.00,,Lad2,,, 2 ,7,SW,0.00,46.24,45.00,0.00,0.00,0.00,Diag1_S5_C,Diag1_S6_S5,Spur1, 2 ,6,SW,0.00,42.48,52.50,0.00,0.00,0.00,Diag1_S6_S5,Diag1_S7_S6,L10, 2 ,5,SW,0.00,38.72,60.00,0.00,0.00,0.00,Diag1_S7_S6,Diag1_S1_S7,L9, 2 ,8,SW,0.00,46.24,30.00,0.00,0.00,0.00,Diag2_C_S8,Diag2_S8_S4,L12, 2 ,9,SW,0.00,32.00,30.00,0.00,0.00,0.00,L12,L12b,Lad1, 2 ,10,SW,0.00,20.00,22.50,0.00,0.00,0.00,L13,L13b,Lad2, 2 ,X1,X,0.00,50.00,37.50,0.00,0.00,0.00,,,, 3 ,T101,S,60.00,20.00,0.00,80.00,0.00,0.00,12,13,,Mainline-N 3 ,T102,C,31.42,80.00,20.00,270.00,360.00,20.00,13,T103,,M-NE 3 ,T103,S,35.00,100.00,20.00,100.00,55.00,0.00,T102,T104,,Mainline-E 3 ,T104,C,31.42,80.00,55.00,0.00,90.00,20.00,T103,14,,M-SE 3 ,T105a,S,6.00,80.00,75.00,74.00,75.00,0.00,14,18,, 3 ,18,SW,0.00,74.00,75.00,0.00,0.00,0.00,T105a,T105b,S18_Div, 3 ,T105b,S,48.00,74.00,75.00,26.00,75.00,0.00,18,17,,Mainline-S 3 ,17,SW,0.00,26.00,75.00,0.00,0.00,0.00,T105c,T105b,S17_Div, 3 ,T105c,S,6.00,26.00,75.00,20.00,75.00,0.00,17,11,, 3 ,S18_Div,C,5.24,74.00,55.00,90.00,105.00,20.00,18,S18_Diag,, 3 ,S18_Diag,S,4.20,68.82,74.32,64.77,73.23,0.00,S18_Div,S18_Rev,, 3 ,S18_Rev,C,5.24,59.59,92.55,270.00,285.00,20.00,Siding_S_Mid,S18_Diag,, 3 ,Siding_S_Mid,S,19.18,59.59,72.55,40.41,72.55,0.00,S18_Rev,S17_Rev,,Siding-S 3 ,S17_Rev,C,5.24,40.41,92.55,255.00,270.00,20.00,S17_Diag,Siding_S_Mid,, 3 ,S17_Diag,S,4.20,35.23,73.23,31.18,74.32,0.00,S17_Rev,S17_Div,, 3 ,S17_Div,C,5.24,26.00,55.00,75.00,90.00,20.00,S17_Diag,17,, 3 ,T106,C,31.42,20.00,55.00,90.00,180.00,20.00,11,T107,,M-SW 3 ,T107,S,35.00,0.00,55.00,0.00,20.00,0.00,T106,T108,,Mainline-W 3 ,T108,C,31.42,20.00,20.00,180.00,270.00,20.00,T107,12,,M-NW 3 ,11,SW,0.00,20.00,75.00,0.00,0.00,0.00,T106,T105c,Xover15_11, 3 ,12,SW,0.00,20.00,0.00,0.00,0.00,0.00,T108,T101,S12_Div, 3 ,13,SW,0.00,80.00,0.00,0.00,0.00,0.00,T102,T101,S13_Div, 3 ,14,SW,0.00,80.00,75.00,0.00,0.00,0.00,T104,T105a,Xover16_14, 3 ,T1,S,54.00,23.00,4.90,77.00,4.90,0.00,2,3,,Inner-N 3 ,T2,C,31.42,77.00,24.90,270.00,360.00,20.00,3,T3,,I-NE 3 ,T3,S,25.20,97.00,24.90,97.00,50.10,0.00,T2,T4,,Inner-E 3 ,T4,C,31.42,77.00,50.10,0.00,90.00,20.00,T3,4,,I-SE 3 ,T6,C,31.42,23.00,50.10,90.00,180.00,20.00,1,T7,,I-SW 3 ,T7,S,25.20,3.00,50.10,3.00,24.90,0.00,T6,T8,,Inner-W 3 ,T8,C,31.42,23.00,24.90,180.00,270.00,20.00,T7,2,,I-NW 3 ,1,SW,0.00,23.00,70.10,0.00,0.00,0.00,T6,T5c,T12a, 3 ,2,SW,0.00,23.00,4.90,0.00,0.00,0.00,T8,T1,T13a, 3 ,3,SW,0.00,77.00,4.90,0.00,0.00,0.00,T2,T1,T9, 3 ,4,SW,0.00,77.00,70.10,0.00,0.00,0.00,T4,T5a,T14, 3 ,T9,S,42.33,50.00,37.50,77.00,4.90,0.00,T12d,3,,XR-NE 3 ,T14,S,42.33,50.00,37.50,77.00,70.10,0.00,T13b,4,,XR-SE 3 ,7,SW,0.00,44.04,44.69,0.00,0.00,0.00,T12d,T12c,T15, 3 ,6,SW,0.00,38.09,51.88,0.00,0.00,0.00,T12c,T12b,T16, 3 ,5,SW,0.00,32.13,59.08,0.00,0.00,0.00,T12b,T12a,T17, 3 ,T15,S,38.54,5.00,44.69,43.54,44.69,0.00,,7,,spur3 3 ,T16,S,32.59,5.00,51.88,37.59,51.88,0.00,,6,,spur2 3 ,T17,S,22.63,9.00,59.08,31.63,59.08,0.00,,5,,spur1 3 ,T19,S,11.54,32.00,30.45,43.54,30.45,0.00,9,8,, 3 ,8,SW,0.00,44.04,30.45,0.00,0.00,0.00,T13b,T13a,T19, 3 ,9,SW,0.00,32.00,30.45,0.00,0.00,0.00,T19,T18,T20, 3 ,T18,S,26.50,5.00,30.45,31.50,30.45,0.00,,9,,spur4 3 ,T20,S,13.57,20.00,23.41,31.50,30.45,0.00,10,9,, 3 ,10,SW,0.00,20.00,23.41,0.00,0.00,0.00,T20,T21,T22, 3 ,T21,S,14.50,5.00,23.41,19.50,23.41,0.00,,10,,spur5 3 ,T22,S,9.05,14.00,16.48,19.50,23.41,0.00,R1,10,,spur6 3 ,R1,S,5.00,9.00,16.48,14.00,16.48,0.00,,T22,, 3 ,X1,X,0.00,50.00,37.50,0.00,0.00,0.00,,,, 3 ,T5a,S,5.00,77.00,70.10,72.00,70.10,0.00,4,16,, 3 ,16,SW,0.00,72.00,70.10,0.00,0.00,0.00,T5b,T5a,Xover16_14, 3 ,T5b,S,44.00,72.00,70.10,28.00,70.10,0.00,16,15,,Inner-S 3 ,15,SW,0.00,28.00,70.10,0.00,0.00,0.00,T5b,T5c,Xover15_11, 3 ,T5c,S,5.00,28.00,70.10,23.00,70.10,0.00,15,1,, 3 ,Xover16_14,S,9.38,72.00,70.10,80.00,75.00,0.00,16,14,, 3 ,Xover15_11,S,9.38,28.00,70.10,20.00,75.00,0.00,15,11,, 3 ,S12_Div,C,5.24,20.00,20.00,270.00,285.00,20.00,12,S12_Diag,, 3 ,S12_Diag,S,4.20,25.18,0.68,29.23,1.77,0.00,S12_Div,S12_Rev,, 3 ,S12_Rev,C,5.24,34.41,-17.55,105.00,90.00,20.00,S12_Diag,Siding_Mid,, 3 ,Siding_Mid,S,31.18,34.41,2.45,65.59,2.45,0.00,S12_Rev,S13_Rev,,Siding1 3 ,S13_Rev,C,5.24,65.59,-17.55,90.00,75.00,20.00,Siding_Mid,S13_Diag,, 3 ,S13_Diag,S,4.20,70.76,1.77,74.82,0.68,0.00,S13_Rev,S13_Div,, 3 ,S13_Div,C,5.24,80.00,20.00,255.00,270.00,20.00,S13_Diag,13,, 3 ,T12a,S,14.31,23.00,70.10,32.13,59.08,0.00,1,5,,XR-NW 3 ,T12b,S,9.35,32.13,59.08,38.09,51.88,0.00,5,6,,XR-NW 3 ,T12c,S,9.33,38.09,51.88,44.04,44.69,0.00,6,7,,XR-NW 3 ,T12d,S,9.34,44.04,44.69,50.00,37.50,0.00,7,T9,,XR-NW 3 ,T13a,S,33.10,23.00,4.90,44.04,30.45,0.00,2,8,,XR-SW 3 ,T13b,S,9.23,44.04,30.45,50.00,37.50,0.00,8,T14,,XR-SW With the library saved and PicoRR.bas loaded, press F2 to run (which loads up the database manager in the user program); type "make"<Enter> and the csv files will be processed to create the fixed format roster.dat and segments.dat, as well as indexes. Then F2 to run the user program (PicoRR), and, for instance, "3" to select layout3. At the "DISPATCH>" prompt, "?" will show you the layout.hlp document. ~ PicoRR.zip Edited 2026-03-07 00:39 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on FOTS |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |