Define Left 0 Define Right 1 Define Forward 2 Define Back 3 Define High On Define Low Off Define True 1 Define False 0 Define Test Off Define LogMode Off Define FrontFreeTime 10 Define DelayToGetStable 30 Define MaxPower 255 'Maximal 255 Minimal 101 Define MinPower 130 'Minimal 100 Define MowTime 3 '3 hour mowing cycle 'Outputs Define LeftLed Port[1] Define RightLed Port[2] Define BumperLed Port[3] Define Led4 Port[4] Define Led5 Port[5] Define LeftDir Port[6] Define RightDir Port[7] Define MowMotor Port[8] 'Inputs Define LeftRF Port[9] Define RightRF Port[10] Define Bumper Port[11] Define LeftMotor DA[1] Define RightMotor DA[2] Define TempB Byte Define TempW Word Define Dir Byte Define TurnDir Byte Define TurnTime Byte Define LostCounter Word Define TimeStamp Word Define StopMode Byte '0 = Slow stop 1 = Direct stop Gosub InitUdo If Test Then Goto TestMode MowMotor = On '#WaitForSpin 'If Freq2 < 43 Then Goto WaitForSpin 'Wait while mowmotor is spinning Dir = Forward Gosub DriveMotor TurnTime = 0 #GoMowing LostCounter = LostCounter + 1 'If (Minute >= 0) And LeftRF Then Goto FindHome If Not Bumper Then Gosub ProcBumper If Not LeftRF Then Gosub ProcLeftRF If Not LeftRF And Not RightRF Then Gosub ProcMidRF If Not RightRF Then Gosub ProcRightRF 'If Freq2 < 43 Then Gosub ProcBumper If LostCounter > 8000 Then Gosub EmergencyHalt 'Has to be calculated 32500 = 7.5 min If Hour = MowTime Then Goto UDOSleep If LostCounter Mod 4 = 0 Then Gosub ToggleLeds 'Blink leds while running Goto GoMowing #TestMode If Not Bumper Then BumperLed = On Else BumperLed = Off If Not LeftRF Then LeftLed = On Else LeftLed = Off If Not RightRF Then RightLed = On Else RightLed = Off Print Freq2 Goto TestMode #ToggleLeds Tog LeftLed Tog RightLed Return #FindHome LostCounter = LostCounter + 1 If Minute = 4 Then Goto UDOSleep If LostCounter > 8000 Then Gosub EmergencyHalt 'has to be calculated 32500 = 7.5 min If Not LeftRF Then Goto LeftRFDetect Goto NotLeftRFDetect Goto FindHome #LeftRfDetect LeftMotor=MaxPower : RightMotor=MaxPower-90 Goto FindHome #NotLeftRfDetect LeftMotor=MaxPower-90 : RightMotor=MaxPower Goto FindHome #LeaveHome Gosub ResetTime Dir = Left Gosub DriveMotor Gosub PowerDownMotor Dir = Forward Gosub DriveMotor Goto GoMowing #ProcLeftRF LeftLed = On : RightLed = Off LostCounter = 0 StopMode = 0 'Slow stop TurnDir = Left : Gosub CollisionProcedure Return #ProcMidRf LeftLed = On : RightLed = On LostCounter = 0 StopMode = 0 'Slow stop TurnDir = Abs(Rand Mod 2) : Gosub CollisionProcedure Return #ProcRightRF LeftLed = Off : RightLed = On LostCounter = 0 StopMode = 0 'Slow stop TurnDir = Right : Gosub CollisionProcedure Return #ProcBumper BumperLed = On StopMode = 1 'Direct stop TurnDir = Abs(Rand Mod 2) : Gosub CollisionProcedure Return #CollisionProcedure If StopMode = 0 Then Gosub PowerDownMotor Else Gosub MotorOff Pause DelayToGetStable Dir = Back Gosub DriveMotor Pause FrontFreeTime Gosub PowerDownMotor Dir = TurnDir Gosub TurnTimeCalculate Gosub SaveData Gosub DriveMotor Pause TurnTime Gosub PowerDownMotor Pause DelayToGetStable Dir = Forward Gosub DriveMotor LeftLed = On : RightLed = Off : BumperLed = Off Return #TurnTimeCalculate 'Make turns from 20 to 180 degrees with a lot small turns TempB = Rand TempB = TempB SHR 1 If TempB >= 47 Then TempB = TempB - 47 If TempB < 30 Then TempB = 0 TurnTime = TempB Randomize Timer Return #DriveMotor On Dir Gosub SetDriveLeft,SetDriveRight,SetDriveForward,SetDriveBack Gosub PowerUpMotor Return #InitUdo MowMotor = Off Gosub MotorOff Gosub ResetTime StopMode = 0 TurnTime = 0 LostCounter = 0 For TempB = 1 to 10 LeftLed=On: Pause 10 : LeftLed=Off BumperLed=On: Pause 10 : BumperLed=Off RightLed=On: Pause 10 : RightLed=Off Next TempB LeftLed = On If LogMode = On Then Open# For Write 'Clear Log and open it for write' Close# Return #SetDriveLeft LeftDir=On:RightDir=Off:LeftMotor=Off:RightMotor=Off Return #SetDriveRight LeftDir=Off:RightDir=On:LeftMotor=Off:RightMotor=Off Return #SetDriveForward LeftDir=On:RightDir=On:LeftMotor=Off:RightMotor=Off Return #SetDriveBack LeftDir=Off:RightDir=Off:LeftMotor=Off:RightMotor=Off Return #MotorOff LeftMotor=Off:RightMotor=Off Return #MotorOn LeftMotor=On:RightMotor=On Return #PowerUpMotor TempB = MinPower #PUC LeftMotor=TempB:RightMotor=TempB TempB=TempB+1 If TempB < MaxPower Then Goto PUC Return #PowerDownMotor TempB = MaxPower #PDC LeftMotor=TempB:RightMotor=TempB TempB=TempB-1 If TempB > MinPower-100 Then Goto PDC LeftMotor=0:RightMotor=0 Return #SaveData 'Store Data in LogFile "TotalSecond:Direction:Angle" If LogMode = Off Then Return Open# For Append TimeStamp = (Minute * 60) + Second If FileFree Then Print# TimeStamp If FileFree Then Print# Dir If FileFree Then Print# TurnTime Close# Return #ResetTime Year = 0:Month = 0:Day = 0:Hour = 0:Minute = 0:Second = 0 Return #EmergencyHalt Gosub MotorOff MowMotor = Off LeftLed = Off : RightLed = Off SlowMode On LeftLed = On : RightLed = On 'Add beep Goto EmergencyHalt 'EndEmergencyHalt #UDOSleep MowMotor = Off Gosub MotorOff Gosub ResetTime SlowMode On #WaitToMowAgain ''If Minute = 1 Then Goto LeaveHome 'Weather and temp routine here reset time Goto WaitToMowAgain 'EndSleep