Script error

5 years 4 months ago - 5 years 4 months ago #29530800 by buchjyot
Script error was created by buchjyot
Hi I am running this code in my roboteq simulator,all I want to do is, read from can for message, if there no message in certain time, go and set parameter for control loop. and do it again. for safe operation i am considering that if there is 3 consecutive false message then set the parameter and resetval is called.

'Script for recieving data over CAN and stoping of Traction loop if the data is not recieved
resetval:
bool flag[20] = {0};'{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int datarate = 1000;
int VAR = 0;
int i = 0;

loop2:
VAR = 0;
VAR = getvalue(_CAN,1)'recieve the data and store in a varialbe VAR
if(VAR!=0) then 'that means you have recieved somthing
{ counter = counter + 1;
wait(datarate);
goto loop2;
}
else
{ flag = 1;
i = i + 1;
if (flag[i-1]==1 && flag[i-2]==1 && flag[i-3]==1)then '3 CONSECUTIVE missed messages_ loss of communicaiton
goto loop3;
else
{
goto loop2;
}
}
loop3:
i=0;
set_command(position_feedback=0)'send a command to traction loop to zero
wait(120000) 'give the time of 2 minutes for the operator to fix the problem
goto resetval 'reset vales and start counting


I am getting an error as shown in attached file.
Attachments:

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

5 years 4 months ago #29530801 by TechSupport
Replied by TechSupport on topic Script error
Your if then statements are nested in a manner that is not correct is what it is telling you.

You have an else condition after another else condition. If you want a multi-conditional argument, then you would use the elseif.

Example:

If a = b then
take action
elseif a = c then
take different action
else
take no action
end if

The "else" condition is in the event all previous arguments are not met, it will be the default answer or path it will take. From my experience programming, you only use one per "if then" loops.
The following user(s) said Thank You: buchjyot

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

5 years 4 months ago #29530802 by TechSupport
Replied by TechSupport on topic Script error
In your particular case, you can close out the first else condition by simply adding end if to the script.

loop2:
VAR = 0;
VAR = getvalue(_CAN,1)'recieve the data and store in a varialbe VAR
if(VAR!=0) then 'that means you have recieved somthing
{ counter = counter + 1;
wait(datarate);
goto loop2;
}
else
{ flag = 1;
i = i + 1;
end if ' This closed out the if statement with the else condition.

' begins new if then argument

if (flag[i-1]==1 && flag[i-2]==1 && flag[i-3]==1)then '3 CONSECUTIVE missed messages_ loss of communicaiton
goto loop3;
else
{
goto loop2;
end if
}
}

loop3:
i=0;
set_command(position_feedback=0)'send a command to traction loop to zero
wait(120000) 'give the time of 2 minutes for the operator to fix the problem
goto resetval 'reset vales and start counting
The following user(s) said Thank You: buchjyot

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

5 years 4 months ago #29530803 by buchjyot
Replied by buchjyot on topic Script error
Thanks for the reply, but i also want to know about declaring array elements all to zero, is that i have done in above script right ?

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

5 years 4 months ago - 5 years 4 months ago #29530804 by TechSupport
Replied by TechSupport on topic Script error
If you have say 2 variables(keep things simple), and they are all integers(number values) then you can initialize those variables with 0 at the beginning of the script before the loop begins.

Example:

dim a as integer

a1 = 0
a2 = 0

'let say that a is var1 variable that changes the outcome of the above that were preset to 0.

top:
a = getvalue(_Var, 1)
if a = 1 then
a1 = 10
else
a2 = 10
end if
wait(1)
goto top

This means before it got to the top: loop label header, both of these values were initialized to 0.
The following user(s) said Thank You: buchjyot

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

5 years 4 months ago #29530811 by buchjyot
Replied by buchjyot on topic Script error
I dont understand what is this error

dim flag[20] as boolean
dim datarate as integer
dim i as integer
dim j as integer
dim VAR as integer
resetval:
i = 0
VAR = 0
datarate = 1000

for j = 0 Andwhile j<20
flag[j] = 0;

Next
Attachments:

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

5 years 4 months ago #29530812 by buchjyot
Replied by buchjyot on topic Script error
i got the point, it doesn't allow semi colon to work

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

Moderators: tonysantoni
Time to create page: 0.124 seconds