'################################################### '-----------------SmartConsole.bas----------------- 'This code was created by Lee von Kraus, Summer 2003 'For SMARTSEA, a Semi-autonomous, Modular, 'and Affordable Research Tool for Submersed Ecosystem Analysis 'This code should be run by a QBasic compiler on a laptop, 'connected to a BS2sx Basic Stamp (which is running SMARTSEA_2003.bsx) 'via a serial cable. '################################################### 'first coordinate is any corner of box '2nd coord is other corner (can be bottom left or top right) 'y '| '+--->x 'if ever want to keep a record of the sensor values: 'OPEN "file.txt" FOR APPEND AS #1 'To print to a file, simply open the file in APPEND, and type PRINT #1, 'followed by text or variables. To read files open it with INPUT and 'then type INPUT #1, followed by variables to read in to. 'time: 'hr = VAL(TIME$) 'min$ = MID$(TIME$, 4, 2) 'sec$ = MID$(TIME$, 7, 2) '################--initialize variables--################# CONST pi = 3.14 CONST YES = 1 CONST NO = 0 CONST HeadingPos = 0 CONST PressurePos = 1 CONST SpeedPos = 2 CONST TimePos = 3 CONST LightsPos = 4 numvals = 8 '<-number of values in each mission step ATilt = 20 'set to arbitrary values (just so can see var declarations up here) ARoll = 20 ARoll2 = 20 AWest = 20 Pressure = 500 xadd = 0 yadd = 0 rdy = NO 'so we know when to send laptopDat or mission steps to the bs DIM degree$(1): 'create array DEGREE to hold data from stamp FOR x = 0 TO 1 degree$(x) = "0" NEXT DIM Mssn$(60): 'create array to hold 10 mission steps (5 vals per step, and one info val) FOR x = 0 TO 51 Mssn$(x) = "0" NEXT rmspeed = 30 lmspeed = 30 fmspeed = 30 bmspeed = 30 z = 0 CurrentStep = 1 '######################################################### '################--MAIN--################################# '######################################################### '================================================== '===================GET Text File Input============ '================================================== 'get plans from text file (read whole thing into a big array) OPEN "c:\mission.txt" FOR INPUT AS #3 INPUT #3, Mssn(0) FOR x = 1 TO (Mssn(0) * numvals) INPUT #3, Mssn(x) NEXT CLOSE #3 PRINT "got text file shite" CLOSE 'just in case port is open OPEN "com1:9600,n,8,1,CD0,CS0,DS0,RS" FOR INPUT AS #1 ' ,CD0 = zero milliseconds timeout on the data carrier detect line (DCD) ' ,CS0 = zero milliseconds timeout on the clear to send line (CTS) ' ,DS0 = zero milliseconds timeout on the data set ready line (DS) ' ,RS" = suppress detection of request to send (RTS) SCREEN (13) JustStartedStep = YES ' The stamp needs these next two lines to clear the DTR bit 'tcmp = INP(&H3FC) 'OUT &H3FC, tcmp AND 254 '================================================== '===================Start Main Loop================ '===================and initialize================= mainloop: IF z > 5 THEN GOTO finished END IF rdy = NO fmspeed = 10 'PRINT "started main loop" '================================================== '===================GET SERIAL INPUT=============== '================================================== 'PRINT "starting wait for the x=5" waiting: degree$(0) = INPUT$(1, #1) 'x = VAL(degree$(0)) 'PRINT "x: ", x IF degree$(0) = "s" THEN GOTO collect ELSE GOTO waiting END IF collect: 'PRINT "collecting data" '========== A_Tilt (forward to back tilt) degree$(0) = INPUT$(1, #1) degree$(0) = INPUT$(3, #1) AWest = VAL(degree$(0)) '========== A_Roll (left to right roll) degree$(0) = INPUT$(1, #1) degree$(0) = INPUT$(3, #1) ARoll = VAL(degree$(0)) '=========== A_West (compass heading) degree$(0) = INPUT$(1, #1) degree$(0) = INPUT$(3, #1) ATilt = VAL(degree$(0)) '=========== temp degree$(0) = INPUT$(1, #1) degree$(0) = INPUT$(3, #1) '<----give it a var!!!! '=========== Pressure degree$(0) = INPUT$(1, #1) degree$(0) = INPUT$(3, #1) Pressure = VAL(degree$(0)) degree$(0) = INPUT$(1, #1) degree$(0) = INPUT$(3, #1) 'the 2nd pressure byte !!!!<---fix '=========== whether or not to send mission plans degree$(0) = INPUT$(1, #1) degree$(0) = INPUT$(3, #1) rdy = VAL(degree$(0)) 'PRINT "ATilt: ", ATilt, "ARoll: ", ARoll, "AWest: ", AWest, "RDY: ", RDY PRINT "rdy:"; rdy, cr IF NOT rdy = 1 THEN GOTO DisplayVals ELSE WaitForRdy1: degree$(0) = INPUT$(3, #1) IF degree$(0) = "RDY1" THEN GOTO PreparePlans ELSE GOTO WaitForRdy1 END IF PreparePlans: PRINT "preparing plans" MssnOver = NO '<-bs will stop sending RDY1's after a mission is decalred over 'so if you're here, you know you're right before the mission is decalred over, 'or a new mission has begun. So MssnOver=NO is ok to set here 'since missions are declared over at the beginning of a nonexisting step, 'juststartedstep will stay "YES"; the nonexistent step never started '========================================================= 'check if mission steps are completed IF CurrentStep >= Mssn(0) THEN MssnOver = YES CurrentStep = 1 GOTO SendPlans END IF '========================================================= 'set thrust motor speeds to the speed the mission asks for '(they will be adjusted for any necessary turning to stay on mission heading) lmspeed = Mssn((CurrentStep * numvals) - (numvals - SpeedPos)) rmspeed = lmspeed '========================================================= 'slow appropriate motor down if need gradual turn 'reverse appropriate motor if need severe turn PRINT "setting speeds" IF Mssn((CurrentStep * numvals) - (numvals - HeadingPos)) > AWest THEN IF Mssn((CurrentStep * numvals) - (numvals - HeadingPos)) < AWest + 10 THEN lmspeed = lmspeed - lmspeed / 5 ELSE lmspeed = -lmspeed / 5 END IF END IF IF Mssn((CurrentStep * numvals) - (numvals - HeadingPos)) < AWest THEN IF Mssn((CurrentStep * numvals) - (numvals - HeadingPos)) > AWest + 10 THEN rmspeed = rmspeed - rmspeed / 5 ELSE rmspeed = -rmspeed / 5 END IF END IF '========================================================= 'set the forward vertical motor speed related to how far off the mission depth it is IF Mssn((CurrentStep * numvals) - (numvals - PressurePos)) > Pressure THEN IF Mssn((CurrentStep * numvals) - (numvals - PressurePos)) < Pressure + 10 THEN fmspeed = fmspeed + fmspeed / 5 ELSE fmspeed = fmspeed + fmspeed / 2 END IF END IF IF Mssn((CurrentStep * numvals) - (numvals - PressurePos)) < Pressure THEN IF Mssn((CurrentStep * numvals) - (numvals - PressurePos)) > Pressure - 10 THEN fmspeed = -(fmspeed + fmspeed / 5) ELSE fmspeed = -(fmspeed + fmspeed / 2) END IF END IF '========================================================= 'set lights on/off bit IF Mssn((CurrentStep * numvals) - (numvals - LightPos)) = 1 THEN Lights = YES ELSE Light = NO END IF '========================================================= 'increment the current step if the step's time has passed 'first need to pick out the minutes from the system clock time FOR x = 1 TO LEN(TIME$) - 2 temp$ = MID$(TIME$, (LEN(TIME$) - 2) - x, 1) IF temp$ = ":" THEN GOTO GotMins END IF NEXT GotMins: min% = VAL(MID$(TIME$, y + 1)) hour% = VAL(MID$(TIME$, y - 1)) IF JustStartedStep = YES THEN StartMin% = min% StartHour% = hour% JustStartedStep = NO END IF 'now compair time with mission step time to see if need to increment the step# IF StartHour% = hour% THEN IF min% - StartMin% > Mssn((CurrentStep * numvals) - (numvals - TimePos)) THEN CurrentStep = CurrentStep + 1 JustStartedStep = YES END IF ELSE IF ((60 - StartMin%) + min%) < Mssn((CurrentStep * numvals) - (numvals - TimePos)) THEN CurrentStep = CurrentStep + 1 JustStartedStep = YES END IF END IF '========================================================= 'check for keyboard press signifying end of step SendPlans: PRINT "sending plans to stamp" '========================================================= 'send the set of motor speeds and light on/off and missionover flag to the basic stamp CLOSE #1 OPEN "com1:9600,n,8,1,CD0,CS0,DS0,RS" FOR OUTPUT AS #2 PRINT #2, "A" PRINT #2, 0, 0, 255, 255, 100, 11, 0, 1'<--example transmission CLOSE #2 OPEN "com1:9600,n,8,1,CD0,CS0,DS0,RS" FOR INPUT AS #1 'check for keyboard press signifying end of step '================================================== '===============Convert Angles===================== '================================================== DisplayVals: 'PRINT "showing display" ARoll2 = -ARoll '<--A_Roll sent, A_Roll2 derived ARoll2 = (ARoll2 / 180) * pi ATilt = 90 - ATilt '<--A_Tilt sent ATilt = (ATilt / 180) * pi ARoll = 90 - ARoll ARoll = (ARoll / 180) * pi ANorth = -AWest '<--A_West sent, A_North derived ANorth = (ANorth / 180) * pi AWest = 90 - AWest AWest = (AWest / 180) * pi '================================================== '================WRITE HEADINGS==================== '================================================== CLS 'LOCATE 4, 4 'PRINT " - Submersible Position Tracker - " PRINT "Time is:", TIME$ PRINT "Missn Step#:", CurrentStep WINDOW (0, 0)-(1000, 1000) LOCATE 8, 28 '1-25 and 1-80, 2nd number is x (column) PRINT "Tilt:" LOCATE 9, 28 PRINT 90 - ((ATilt * 180) / pi) LOCATE 8, 16 PRINT "Roll:" LOCATE 9, 16 PRINT 90 - ((ARoll * 180) / pi) LOCATE 8, 4 PRINT "Heading:" '================================================== '===================MAKE Tilt GFX================== '================================================== LINE (650, 50)-(950, 1000), 14, B 'center is (800,400), Length of spoke is 100 pixels 'so given an angle, cos(angle)=height/hypotenus yadd = (COS(ATilt)) * 100 xadd = (SIN(ATilt)) * 100 LINE (800, 400)-((800 + xadd), (400 - yadd)), 13 '<--Tilt LINE (800, 400)-((800 - xadd), (400 + yadd)), 13 LINE (800, 394)-((800 + xadd), (394 - yadd)), 13 LINE (800, 394)-((800 - xadd), (394 + yadd)), 13 '================================================== '===================MAKE Roll GFX================== '================================================== LINE (350, 50)-(650, 1000), 14, B yadd = (COS(ARoll)) * 50 xadd = (SIN(ARoll)) * 50 LINE (500, 400)-((500 + xadd), (400 - yadd)), 13 '<--Roll LINE (500, 400)-((500 - xadd), (400 + yadd)), 13 yadd = (COS(ARoll2)) * 20 xadd = (SIN(ARoll2)) * 20 LINE (500, 400)-((500 + xadd), (400 - yadd)), 13 LINE (500, 400)-((500 - xadd), (400 + yadd)), 13 '================================================== '===================MAKE Depth GFX================= '================================================== LINE (350, Pressure)-(950, Pressure), 3, B '================================================== '=================MAKE Heading GFX================= '================================================== LINE (50, 50)-(350, 1000), 14, B 'CIRCLE (200, 400), 160, 4, 0, .1 '<--doesn't work in mode 2 ! '<--tried to draw a segment, didn't work in either mode!! 'CIRCLE (200, 400), 160, 4, , , 20 / 17 '<--previous line makes a good circle in screen mode 1 'CIRCLE (200, 400), 90, 1, , , 9 / 2 '<--previous line makes a good elipse in screen mode 1 '----------- 'CIRCLE (200, 400), 150, 1, -.01, 0 'CIRCLE (200, 400), 150, 2, -1.57, 0 'CIRCLE (200, 400), 150, 3, -3, 0 CIRCLE (200, 400), 140, 4, , , 6 / 10 '<--previous line makes a good circle in screen mode 2 CIRCLE (200, 400), 60, 13, , , 6 / 2 '<--previous line makes a good elipse in screen mode 2 '----north/sout/east/west lines yadd = (COS(AWest)) * 100 xadd = (SIN(AWest)) * 100 LINE (200, 400)-((200 + xadd), (400 - yadd)), 3 '<--east LINE (200, 400)-((200 - xadd), (400 + yadd)), 3 '<--west yadd = (COS(ANorth)) * 140 xadd = (SIN(ANorth)) * 140 LINE (200, 400)-((200 - xadd), (400 + yadd)), 10 '<--north yadd = yadd * (100 / 140) xadd = xadd * (100 / 140) LINE (200, 400)-((200 + xadd), (400 - yadd)), 3 '<--south '================PAUSE================================ GOTO mainloop finished: END