Shop OBEX P1 Docs P2 Docs Learn Events
Changing Variables while Program is Running — Parallax Forums

Changing Variables while Program is Running

I am making a "ballbot" using a propeller. I am at the stage where I need to fine tune the PID. It would be ideal if I could fine tune the PID while the propeller program is running. I have been trying to use HyperTerminal to do this, but I don't seem to have as clue as to what I am doing. If someone could give me a few suggestions, I would appreciate it.

Comments

  • What language are you using?
  • The main loop runs in Spin. That is where I have declared globally the PID multipliers.
  • If you have the ability to code a simple thing on the PC side, you may find that easier. Sending data with a terminal program requires you to interpret ASCII stuff, which takes some effort. Sending raw binary values over a serial port from a PC is comparatively easy.

    I usually do this by sending a header byte or two (like 0x55, 0x44) so the Prop knows that what follows is legitimate data, then send a byte for what parameter you're changing, followed by the 4 bytes for the value itself. It's pretty simple to set up, and C# on the PC side works really well for simple stuff like that.

    If you want to do it on the Prop and a terminal, and you want to keep it simple, do something like this: Interpret digits 1 through 9 as P strength values from 100 to 900, and interpret 'QWERTYUIOP' characters as strengths for another parameter.

    That way, you don't have to provide a full proper interface, but you can noodle the numbers really easily.

    You could also try something like using 'Q' and 'A' to increment and decrement one parameter, 'W' and 'S' to increment/decrement another one, and so on. Every time you change a value, have the Prop display the name and current setting of it so you can keep track.

    Jason
  • Thank you Jason for your help. I will look into your suggestions.
  • JasonDorieJasonDorie Posts: 1,930
    edited 2015-11-20 22:23
    You're welcome. Not sure if you've used the character input routines from FullDeplexSerial before, but they're quite simple.

    Something like this:
    obj
      fds : "FullDuplexSerial"
    
    pub GetUserInput | ch
    
      ch := fds.rx
      if( ch == -1 )
        return
    
      if( ch == "q" )
        P += 10
      if (ch == "a" )
        P -= 10
    
    

    ... and so on. I can't remember if the function is called rx or rxCheck, but it's one of those. It returns -1 if no character was present, or a valid byte value of the character if there was one.
  • I had to tune a very sensitive PID loop and I found that ViewPort was the easiest interface. Not only can you change the PID parameters on the ViewPort screen, but you can run a real-time trace of the output on the same screen.
Sign In or Register to comment.