Shop OBEX P1 Docs P2 Docs Learn Events
Andy Lindsay's PID Object — Parallax Forums

Andy Lindsay's PID Object

joeldjoeld Posts: 49
edited 2008-03-05 06:06 in Propeller 1
I had a couple of questions reguarding the code in Andy's PID object. In the init method he uses longmove to copy the variables passed to the method into similar variables defined in the VAR section of the object. Is the point of this so that these values will be available to other methods in the object? Is my understanding correct that·variables passed to a method are only readable in that method and not other methods in the same object? Also is the longmove used because it generates less code that using the := to assign the values to local variables? Are there ever issues with variables not being written in sequential locations and this causing problems with this type of code?

PUB init (_Kp, _Ki, _Kd, setPoint, offset, maxArea, minArea)
· ' Start floating point object.
· f.start
· ' Set values of kp, ki, etc.
· longmove(@kp, @_Kp, 7)

Sorry if these are mundane questions but I'm trying to get a grasp of what's going on?

Comments

  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-05 06:06
    joeld said...
    Is the point of this so that these values will be available to other methods in the object? Is my understanding correct that variables passed to a method are only readable in that method and not other methods in the same object?
    I'm not sure about the first bit because I haven't looked at the code. You are correct that variables that are passed to a method are only readable in that method and not others in the same object. This is actually quite true, if you call another method in the same object than the variables will still be on the stack but you don't really have a way of knowing where they are.
    said...
    Also is the longmove used because it generates less code that using the := to assign the values to local variables?
    Yes, longmove uses less space and is a lot quicker. I think that you would find that it is quicker than even starting a cog in assembly to do the same job.
    said...
    Are there ever issues with variables not being written in sequential locations and this causing problems with this type of code?

    PUB init (_Kp, _Ki, _Kd, setPoint, offset, maxArea, minArea)
    ' Start floating point object.
    f.start
    ' Set values of kp, ki, etc.
    longmove(@kp, @_Kp, 7)
    If you use this type of code than the variables in the other object must be sequential and in the same order or else the code won't work.
Sign In or Register to comment.