RobotStudio event

function argument is not a is not a constant expression

kschmid
kschmid
edited August 2019 in RAPID Programming
This must be a pretty trivial error, can I pass arguments as constant?
Or do I even have to? radius should be a copy here ?

    PROC get_pitch(num turnSpacing, num radius, INOUT num slope_angle)
        CONST num circum := l_PI * 2. * radius;
    ENDPROC

gets me
System1/RAPID/T_ROB1/Module1(317,41): Data declaration error(20): Expression radius is not a constant expression.    5/08/2019 3:57:31 PM    General   
Also getting similar result with FUNC.
num radius is not a copy?

it works with everything in 1 line but that's silly
   PROC get_pitch(num turnSpacing, num radius, INOUT num slope_angle)
        slope_angle := toDegree(ATan(turnSpacing / l_PI * 2. * radius));
    ENDPROC


Post edited by kschmid on

Comments

  • EricH
    EricH
    edited August 2019
    It needs a constant, because you declare and initialize the value at the same line.

    </code>CONST num circum := l_PI * 2. * radius;<br>  ^    ^<br>  |    |<br></pre><br></div><div>You can fix this by doing this for example:</div><div><br></div><div><pre class="CodeBlock"><code>PROC get_pitch(num turnSpacing, num radius, INOUT num slope_angle)<br>        VAR num circum := l_PI;<br>        circum := l_PI * 2. * radius;<br>ENDPROC
    or

    <code>VAR num circum;<br>PROC get_pitch(num turnSpacing, num radius, INOUT num slope_angle)
    circum := l_PI * 2. * radius;
    ENDPROC





  • kschmid
    kschmid
    edited August 2019
    let me try, i think CONST didnt do it.
    Ah, right i need to declare separately. First time i meet a language with that requirement but thanks for your help
  • Hi Eric, Thanks for your answer, which also solved my problem. 

    I am wondering, why seperate the declaration and assignment expression could solve the problem. Is there anything to do the way Robotstudo allocates it's memory?

    Appreciated!