Unexpected end of file

5 years 7 months ago #29530102 by stu_uk
Hello all,

I am completing a program only for an AGV, as a proof of concept in a final year degree project.

Unfortunately, the program will never be downloaded to a controller as the project will more than likely never be built due to cost and time, I am merely using roboteq controllers and magnetic sensors as a proof of concept on how the AGV program would work.

I have based my program on the example program given by roboteq.

I am very new to programming so this a big learning curve for the little time I have.

However, on my script, an error has appeared:

Unexpected end of file, line 112.

Now, as far as I can see end if statements are in place where necessary and the last statement is goto top on line 111.

Notice how the error is on the line after the final line on script? The error relates to a line that doesn't exist.

I can't figure out what is causing it.

Any help would be much appreciated.

Thanks,

Stu.

Please Log in or Create an account to join the conversation.

5 years 7 months ago #29530103 by roboteq
Replied by roboteq on topic Unexpected end of file
This most likeky because you have a if without and end if. Check your code. If you cant figure the problem, paste your code here

Please Log in or Create an account to join the conversation.

5 years 7 months ago #29530104 by stu_uk
Replied by stu_uk on topic Unexpected end of file
Thanks for the very quick reply, I appreciate it. Can't see anything, here is the script (it is far from finished):

' declare variables

dim Gain as integer
dim FullThrottle as integer
dim SlowThrottle as integer
dim StopThrottle as integer
dim TapeDetect as boolean
dim MarkerLeft as boolean
dim MarkerRight as boolean
dim Throttle as integer
dim Tape_Position as integer
dim LineSelect as integer
dim Steering as integer
dim AutoSwitch as boolean 'AGV 'Auto' Switch
dim ManualSwitch as boolean 'AGV 'Manual' Switch
dim StartButton as boolean 'AGV 'Start' Button
dim ResetButton as boolean 'AGV 'Reset' Button
dim DestFMS1Switch as boolean 'AGV FMS1 Destination Select Switch
dim DestFMS2Switch as boolean 'AGV FMS2 Destination Select Switch
dim DestPresetSwitch as boolean 'AGV Preset Destination Select Switch
dim EmergecyStop as boolean 'AGV Emergecny Stop Button
dim CollisionDetectFar as boolean 'AGV Collision Sensor (Detection Far)
dim CollisionDetectNear as boolean 'AGV Collision Sensor (Detection Near)
dim RunState as boolean
dim NotOnStopMarker as boolean
dim StartTimer as integer

' initialise constants

Gain = -7
FullThrottle = 1000 'AGV Full Speed, 3.075MPH or 3000rpm (105rpm with gearbox)
SlowThrottle = 250 'AGV Slow Speed, 0.769MPH or 750rpm (26.25rpm with gearbox)
StopThrottle = 0 'AGV Stopped
StartTimer = 5000 'Timer before AGV moves away

' main loop to repeat every 10ms

top:
wait(10)
' read sensor data
TapeDetect = getvalue (_MGD)
MarkerLeft = getvalue (_MGM, 1)
MarkerRight = getvalue (_MGM, 2)

' read input states and set output states

AutoSwitch = getvalue (_DI, 1)
ManualSwitch = getvalue (_DI, 2)
StartButton = getvalue (_DI, 3)
ResetButton = getvalue (_DI, 4)
DestFMS1Switch = getvalue (_DI, 5)
DestFMS2Switch = getvalue (_DI, 6)
DestPresetSwitch = getvalue (_DI, 7)
EmergencyStop = getvalue (_DI, 8)
CollisionDetectFar = getvalue (_DI, 9)
CollisionDetectNear = getvalue (_DI, 10)

if (StartButton = 1) then SetTimerCount(1, StartTimer) 'If 'start' button is pressed, run the 'StartTimer'
setcommand (_DSET, 1)
setcommand (_DSET, 2)
setcommand (_DSET, 4)
if GetTimerState(1) then RunState = true
setcommand (_DSET, 1)
setcommand (_DRES, 2)
setcommand (_DSET, 4)
if (TapeDetect and GetTimerState(1))
Throttle = SlowThrottle
elseif (TapeDetect and GetTimerState(1) and MarkerLeft)
Throttle = SlowThrottle
elseif (TapeDetect and GetTimerState(1) and MarkerRight)
Throttle = FullThrottle
else
Throttle = StopThrottle
end if

' check switches to select left or right track and set forward / reverse relay
if (DestFMS1Switch = 1)
LineSelect = 2
setcommand (_DSET, 5)
if (DestFMS2Switch = 1)
LineSelect = 1
setcommand (_DSET, 5)
if (DestPresetSwitch = 1)
LineSelect = 1
setcommand (_DRES, 5)
' detect transitioning onto stop markers
if (NotOnStopMarker and MarkerLeft and MarkerRight)
NotOnStopMarker = false 'stop marker not detected again until AGV moves
RunState=false
else
NotOnStopMarker = true
end if

Tape_Position = getvalue (_MGT, LineSelect)
Steering = Tape_Position * Gain
setcommand (_G, 1, Throttle)
setcommand (_G, 2, Steering)

goto top

Please Log in or Create an account to join the conversation.

5 years 7 months ago #29530105 by TechSupport
Replied by TechSupport on topic Unexpected end of file
Try putting in the end if between the setcommands and next if then statement.

if (DestFMS1Switch = 1)
LineSelect = 2
setcommand (_DSET, 5)
end if
if (DestFMS2Switch = 1)
LineSelect = 1
setcommand (_DSET, 5)
end if
if (DestPresetSwitch = 1)
LineSelect = 1
setcommand (_DRES, 5)
end if
The following user(s) said Thank You: stu_uk

Please Log in or Create an account to join the conversation.

5 years 7 months ago #29530106 by stu_uk
Replied by stu_uk on topic Unexpected end of file
Thanks that worked. Now I have this problem though:

163 if (EmergencyStop = 0)
164 Do
165 runstate = false
166 setcommand (_DRES, 6)
167 setcommand (_DSET, 3)
168 setcommand (_ESTOP)
169 Loop Until (Emergency Stop = 1 and ResetButton = 1)
170 end if
171 goto top

ERROR: Syntax error, expected: ) Line 169

Also tried:

163 if (EmergencyStop = 0)
164 Do Until (Emergency Stop = 1 and ResetButton = 1)
165 runstate = false
166 setcommand (_DRES, 6)
167 setcommand (_DSET, 3)
168 setcommand (_ESTOP)
169 Loop
170 end if
171 goto top

ERROR: Syntax error, expected: ) Line 164

Any ideas?

Very, very similar code worked elsewhere in the program, only it started with else not if

Thanks.

Please Log in or Create an account to join the conversation.

5 years 7 months ago #29530107 by roboteq
Replied by roboteq on topic Unexpected end of file
You have EmergencyStop spelled in two words Emergency Stop at that line.

Always put

option explicit

at the very top of your program. This will catch any mispelling of variables.

Please Log in or Create an account to join the conversation.

5 years 7 months ago #29530108 by stu_uk
Replied by stu_uk on topic Unexpected end of file
Perfect, thanks!

Is there any way to copy the code to something like Microsoft Word and maintain the formatting, e.g. colours?

Please Log in or Create an account to join the conversation.

5 years 7 months ago #29530109 by roboteq
Replied by roboteq on topic Unexpected end of file
no. The closest would be Notepad++

It could be possible to create a dictionary for notepad++ with all the microbasic keywords but I volunteer would have to invest the time

Please Log in or Create an account to join the conversation.

5 years 7 months ago #29530110 by roboteq
Replied by roboteq on topic Unexpected end of file
Well, after all, this was something that was in our ToDo list for ages and it was actually fairly simple.

In Notepad++, under the Language menu, go to the Define your language, and import the definition file attached.

Please Log in or Create an account to join the conversation.

5 years 7 months ago #29530111 by stu_uk
Replied by stu_uk on topic Unexpected end of file
Hi, thanks for the help, I really do appreciate it.

However, I can't see any attachment?

Please Log in or Create an account to join the conversation.

Time to create page: 0.105 seconds