Shop OBEX P1 Docs P2 Docs Learn Events
PID following Propeller Bot.spin — Parallax Forums

PID following Propeller Bot.spin

TtailspinTtailspin Posts: 1,326
edited 2010-09-05 21:40 in Robotics
I would like to add a Rudder to My PID following Propeller Bot.
Using a standard servo, how could I make it turn PID style?
I have been trying to do this Myself, using My standard Programming techniques,
But... I seem to have run out of Four Letter Words...:freaked:

I was able to make the Rudder turn slightly(about 10 degrees) to one side.
but nothing proportional by any means.
and sometimes the Left or Right Servos would turn opposite of the expected direction.

So, I My question is, what would I add or change or... to make My Rudder, Rudder.

As an aside, I would also like to add a third forward IR Sensor..
what would be needed for that?

Thanks for any help on this.

Comments

  • FranklinFranklin Posts: 4,747
    edited 2010-08-30 10:55
    First thing to do is show us the code you are trying to get working and tell us what you expect and what you get. That will help us help you.
  • TtailspinTtailspin Posts: 1,326
    edited 2010-08-30 13:25
    I am using the "Propeller following PEKbot v0.90. zip", it is located in the
    Propeller chip forum, in the Propeller Education Kit Labs, Tools, and Applications sticky, down at the bottom of the page.
    I could post it here again if that would be helpfull..

    My version of it is the same except for deletion of the Peizo speaker set up.
    I will post up what little I have done to the code, it is just what I have
    attempted so far, it's lines of code I tried to insert, and then commented out.

    As for what I expect to happen with this code..
    I expect the Rudder Servo to operate in sync with the Left and Right wheel servos.
    I wish the Rudder to swing Left when the robot turns Right, and,
    the Rudder should swing to the Right when the robot turns Left...

    You know, like a Boats Rudder... Push the Tiller handle to Port, and the bow will
    start to point to Starboard...ect.
    Of course the Rudder Movements being Proportional to the Wheel Servo's Movements..

    Here is the Main Part of the Program, like I say, it's just some lines of code that I added then commented out.
    CON
      _xinfreq = 5_000_000                      
      _clkmode = xtal1 | pll16x
      L = 0
      R = 1      
      'M = 2
    VAR
      long servo[2]
      'long servo[3]
     
    OBJ
      schematic : "Propeller Boe-Bot Schematic"
    '  piezo     : "Piezospeaker"
      ir[2]     : "Ir Detector"
      s         : "Servos"
      pid[2]    : "PID"
    '  pid[3]    : "PID"
    '  VDisplay  : "TV_Terminal"
     
    PUB init
      ' Piezospeaker connected to P6, beeps at a frequency of 2637 for
      ' 1 second (2637 cycles).
    '  piezo.beep(6, 2637, 2637)
     
      'Configure IR detectors.
      ir[L].init(8, 9)                   ' IR LED to P8, detector to P9. 
      ir[R].init(14, 15)                     ' IR LED to P14, detector to P15.
      'Variables will be monitored by servos object.  Both are initialized
      'to stop (range is -1000 to 1000 with 0 = stop).
      'servo[11] := 0                       'Rudder Servo
      servo[12] := 0                        'Right Wheel Servo      
      servo[13] := 0                        'Left Wheel Servo
     
      'Pass low to high pins for a contiguous range of servos.  Left servo
      'is connected to P13, right is connected to P12
      s.start(12, 13, @servo)
    '  s.start(11, 13, @servo)
     
    '  VDisplay.Start(24)
     
      'Initialize PID object.  Values were determined through experimentation.
      '                                                            integral
      '                                         set                clamps
      '             kp     ki        kd         point    offset    high low
      pid[L].init(-2.1,   -12.02,   -0.01664,   25.0,    0.0,      5.0, -5.0)
      pid[R].init( 2.1,    12.02,    0.01664,   25.0,    0.0,      5.0, -5.0)
      'pid[M].init(-2.1,   -12.02,   -0.01664,   25.0,    0.0,      5.0, -5.0)
      'Call the main method (otherwise, the program would stop here).
      main                                      
    PUB main | dist[2]', X, Y, LargestValue        'X, Y, and LargestValue are Local variables.                                     
      repeat
        'Get distances
        dist[L] := ir[L].Distance 
        dist[R] := ir[R].Distance 
        'Run distances through PID objects.
        'The outputs are used to update the servo drive variables, which are constantly monitored
        'by the Servos object.  As soon as the variables change, the servos object updates the pulse
        'train to the servos.
        servo[L] := pid[L].calculate(dist[L])
        servo[R] := pid[R].calculate(dist[R])
        'servo[M] := pid[M].calculate(dist[L])- pid[M].calculate(dist[R])
        'X := servo[L]
        'Y := servo[R]
     
        'LargestValue := FindTheLargest(X,Y) 'Calls the function and assigns the
                                              'result to "LargestValue."
        'servo[M] := LargestValue + pid[M].calculate(LargestValue) 
        'servo[M] := pid[M].calculate(LargestValue) - (LargestValue/2)
     
    '    VDisplay.Dec(LargestValue)
    '    
    PRI FindTheLargest (X,Y) : Largest     'Largest returns the result. Note the ":".
      If X > Y
        Largest := X
      Else
        Largest := Y
    
  • ercoerco Posts: 20,256
    edited 2010-08-30 14:57
    Of course, the tiller handle moves opposite from the rudder, since there's a pivot in between. Push the tiller handle left, the rudder moves right, the boat turns right.
  • TtailspinTtailspin Posts: 1,326
    edited 2010-08-30 16:16
    However Ye LandLubbers want's to describe Yer Left an Right's is fine by Me...

    I'm not building a boat, I guess I could have used a Red Wagon as an example,
    but then You would have to picture yourself sitting in the wagon as opposed to Pulling the Wagon...

    But.. then again I'm not Building a Wagon either... Uhmm, what would You call this thing?
    600 x 800 - 353K
    600 x 800 - 341K
    800 x 600 - 285K
  • lardomlardom Posts: 1,659
    edited 2010-09-01 06:56
    When I saw "inapinchrear" I actually thought, :) "...one eyed duck". :)
  • TtailspinTtailspin Posts: 1,326
    edited 2010-09-01 08:41
    The Name "InaPinch" comes from this...
    800 x 600 - 415K
  • lardomlardom Posts: 1,659
    edited 2010-09-01 18:23
    Ttailspin, I like that kind of thinking. I wanted my self-installed screen door to close automatically so I made a spring out of a wire hanger by coiling it around a wooden dowel. A lot of times I'll try to make something from what I have on hand.
  • ercoerco Posts: 20,256
    edited 2010-09-01 19:59
    Sweet robot, Ttailspin! That must be a pretty beefy servo to turn your steering wheel & tire!
  • TtailspinTtailspin Posts: 1,326
    edited 2010-09-01 22:42
    Thanks, It's all about the Proof of concept, I can Pretty it up later...
    Velcro and Zip ties will one day rule the world...

    erco, the steering Servo is a standard one from Parallax.
    the "Drive" Servos, are continious rotation, also from Parallax.

    The RFID reader, QTI sensors, XBee, and of course the USB Proto Board,
    Are all standard Parallax issue..

    The onboard Joystick is from a Nintindo 64, there is also one for the "Remote"(PPDB).

    The Camera is from some clearance sale...somewhere...
    it just goes for the ride and displays the action on an old tv set.

    The QTI "Arm" is rotated by a racy little standard servo I picked up for 5 bucks..
    the "arm" is used for raising and lowering the Line following QTI sensors,
    it is also used for self defense when surrounded and outnumbered.(see Photo)...

    IR sensors are mounted on some perf board for easy mounting, and adjusting.

    Some extra slide switches and a pushbutton are also installed.

    The Emergency Joystick(see rearview photo), was made in My shop,
    It's made from a 74HC165 shift register, come to think of it, that comes from Parallax too..:lol:

    InaPinch2 when fully loaded, tips the scales at about two and one half pounds.
    800 x 600 - 345K
  • TtailspinTtailspin Posts: 1,326
    edited 2010-09-04 12:00
    Hrmm...
    That is a bit intimadating...
    A "post Yer code" and two drive by's...

    Oh well, ask a stupid question...
  • FranklinFranklin Posts: 4,747
    edited 2010-09-04 18:05
    Hrmm...
    That is a bit intimadating...
    A "post Yer code" and two drive by's...

    Oh well, ask a stupid question...
    ?:confused:
  • TtailspinTtailspin Posts: 1,326
    edited 2010-09-04 19:09
    Mehh..I was grumpy, forget about it..

    Actually I thought that someone would have had allready put a Rudder Servo
    on the back of their Robot Platform, well, it's not just the Rudder Steering,
    It's more about the PID control of the Steering...

    I will keep picking away at it.
  • agfaagfa Posts: 295
    edited 2010-09-04 20:43
    I've read this several times, I'm not sure I understand completely what your expecting the bot to do. Is the "rudder" supposed to have complete control of the direction of the bot? it looks to me that you are only driving the left servo when your using the rudder. You said you get about 10 degrees of motion in one direction. Have you confirmed that the servo is operating correctly, and is capable of full range of motion? Have you tried adjusting the PID gains for the rudder servo? Does it operate as expected without the rudder?
  • TtailspinTtailspin Posts: 1,326
    edited 2010-09-04 22:25
    I originally built this bot without IR/PID wandering ability, all of the steering control,
    came from the N64 Joystick, and I followed it around, for a while..

    then came the Xbee setup, and I can send commands from My PPDB. Remote control style.

    I made it so if I want to turn hard right, then the "Drive" servos turn opposite each other,
    and the Rudder servo turns hard left, and InaPinch spins around on its own axis.
    to turn soft right, like for a circle, then the Rudder turns only about 45 degrees.

    So My Joystick Rudder set up really only has two settings, hard turn and soft turn.
    Plus center setting of course.

    The Rudder servo works better then I had anticipated, when I first tried it out.
    It snaps right or left the full 180 as needed, and really helps with the payload weight distribution.

    Anyway, to be clear, the Rudder works fine, it's just that I would like to add PID control.
    to the Rudder System.
  • agfaagfa Posts: 295
    edited 2010-09-05 04:38
    OK. That makes a little more sense. Your wanting the rudder's steering to cooridinate with the the main servos & all go in the same direction. That actually sounds pretty complicated to me. I haven't actually done anything like that myself so I'm not sure that I can be much help and I haven't used the objects involved either.

    I don't see in your sample code where it's getting commands from a joystick. What I see is, the servos actions are being controlled by the output of the PID based on distance from the IRs. Maybe you could point out in the code where the joystick commands are being used to control the servos.

    For PID control, you have to have some sort of feedback to comare to a setpoint, in the sample the feedback is the distance from the IR, and I'm guessing the setpoint is a preset desired distance. For the rudder to turn "PID style" I'm thinking the setpoint would have to be the differential position of the main servos, and compare it to the actual position of the rudder, to get an error that PID could use.

    I think there would be easier ways to control the rudder.
  • TtailspinTtailspin Posts: 1,326
    edited 2010-09-05 08:19
    agfa, You really should try this out, if You haven't seen a PID Following Robot..
    I think it's one of the greatest things to ever happen to a Robot. at least in the top 5 thats for sure...

    If Anyone has not tried this out, Just run on down to the Parallax store, and set yourself up with either,
    A Boe Bot Kit (easy), or..

    Purchase 2 continious rotation servos, 2 IR sensors, 2 IR leds, ect. ect.(not so easy)..

    Whatever Platform You choose, the sticky at the top of the Propeller Chip forum has the code to use.
    "Propeller following PEKbot v0.90. zip",
    It is a miracle of Modern Science, as written by Andy Lindsay.

    Put Your Robot together,(Rudder not required), load the code into EEPROM, and let it roam...

    Anyways, as far as My Robot(InaPinch), is concerned, let's just forget about Joysticks for now.
    and just figure I am only using the PEKbot code for now.

    The code works great as is, My problem, I want a Rudder too..
    Rudders just look cool to Me.. and, I hate Casters, even the worlds best caster available,
    I.E. Parallax's world famous Billet Machined aluminium wonder caster,
    is not for Me, in fact I hate Casters so much, I have had all them removed from My office chairs...
    But thats just Me..
    I think there would be easier ways to control the rudder.

    Oh... I assure You... I will have a PID controlled Rudder system when finished.
    Or should I perish before hand, My Heirs will complete the Task.. rest assured, there will be a PID Controlled Rudder...

    Lack of Knowledge has never stopped Me from making decisions before...:skull:
  • TtailspinTtailspin Posts: 1,326
    edited 2010-09-05 08:55
    Now, as for this...
    [HTML]
    For PID control, you have to have some sort of feedback to comare to a setpoint,
    in the sample the feedback is the distance from the IR,
    and I'm guessing the setpoint is a preset desired distance.
    For the rudder to turn "PID style" I'm thinking the setpoint
    would have to be the differential position of the main servos,
    and compare it to the actual position of the rudder, to get an error that PID could use.
    [/HTML]
    from what I understand of it, is the IR's give constant feedback to the PID Calculator,
    and the Calculation is used for the Drive Servos, Proportionally...
    I.E if the wall is right in front of the Robot, it will do a 180 degree turn from the wall.
    if the wall is just to the Left front of the Robot, it will just slightly turn Right, away from the wall.
    Pretty cool stuff..

    I did try to use the Servo[L] and Servo[R] calculations to activate the Rudder,
    taking the largest value of the two, and then divide that number down, and putting that to the Rudder Servo.

    also tried using the Lowest Value of the two, and put that to the Rudder,

    then I tried taking both numbers, and put that into its own PID Calculation, No luck at all though...

    I tried to just use this...(in different combinations)
        outa[RudderPin]~~
        waitcnt(Pulsout * SmallestValue / LargestValue + cnt)
        'waitcnt(Pulsout * (LargestValue-SmallestValue) + cnt)
        'waitcnt(Pulsout * 725 + cnt)
        outa[RudderPin]~
        waitcnt(Pause * 20 + cnt)
    
    But this just makes the Drive Servo's go Backward or at the wrong speed, or not at all..

    In fact, trying to do anything with the Rudder thru the PEKBot Program, makes the Program angry...

    "COG SLAP" is what I have right now...Dang Cogs slapping around inside that little chip...
    Gonna take a screw driver to the back of that chip an see if I can tighten them up some...
  • agfaagfa Posts: 295
    edited 2010-09-05 09:35
    There's nothin' like the sound of "cog slap".

    Have you tried taking the difference in servo speed values? If the values are equal the rudder would be neutral, if not a positive value could indicate one direction and a negative value the other, the higher the value the greater the rudder angle. This in fact would be PID rudder control since the servo speed values are the result of PID.

    The beauty of PID is that it's not just a proportional feedback control system. I find the subject fascinating and I am still trying to understand it.

    Sorry I couldn't be more help. Good luck! Post your success.

    agfa

    Edit: After posting this, I see you have tried using the difference. But It shouldn't effect the main servos operation unless you are also adjusting their values in the calculation.

    Once again. Good luck.
  • ercoerco Posts: 20,256
    edited 2010-09-05 11:34
    Pardon me for stating the painfully obvious, but this seems less of a PID problem and more of a chassis mechanical problem. You're going to a lot of trouble to try to accurately steer a non-powered wheel. A castering wheel does what you want simply and for free. That's the benefit of a diffdrive chassis as opposed to an Ackerman or tricycle chassis.

    If you were driving this wheel as well, I could understand your struggle better.

    If this wheel is causing you grief because there is too much weight on it, you would do better to change your chassis layout to keep 95% of your weight on your drive wheels. This has 2 advantages. First, you reduce any turning effects due to a passive caster wheel, and secondly, you keep all your weight on your drive wheels for better traction.

    Captain Obvious :)
  • TtailspinTtailspin Posts: 1,326
    edited 2010-09-05 11:46
    That's just it, I don't believe I am changing the Values of the Drive Servo's...

    Some how, it does effect them though. it's like one of the .spin files is written
    in a way that "Takes Over" more of the Propeller Pins then it should,
    I know that is over simplified, but not sure how to explain it just yet.

    Anyway's, this is a much better direction to take, as I was messing with the difference, but not in the way you describe...
    [HTML]Have you tried taking the difference in servo speed values? If the values are equal the rudder would be neutral, if not a positive value could indicate one direction and a negative value the other, the higher the value the greater the rudder angle. This in fact would be PID rudder control since the servo speed values are the result of PID.
    [/HTML]
    I will explore this..
    thanks for your input.
  • agfaagfa Posts: 295
    edited 2010-09-05 11:52
    erco,

    I don't think it's a PID problem or a mechanical problem, just a desire to conquer.
  • TtailspinTtailspin Posts: 1,326
    edited 2010-09-05 13:11
    A Third Drive Wheel is absopositivaly in the works...

    First things first though. A walk before I run, kinda thing.

    I can tell You, that the weight balance I've been using is around 80% to 85% on the drive wheels.
    This thing turns very smoothly, no weight issues, and very little tail drag in sharp manuvers.

    Right now, all that is required to Join in the Fun is...
    The schematic of the Hardware needs, And the code from the Sticky.
    (I've included My version of the Schematic)

    I believe any Board will work, Be it the BOE, any one of the Proto Boards, perhaps even the PPDB.
    anything that can spin 2 continious rotation, and 1 standard servo at the same time.
    and it needs to drive 2 IR emmiter Leds, and 2 IR recievers,(the three wire ones).

    It does'nt even have to turn a Rudder,(if you hate rudders, like I hate casters.)
    Just make the Standard Servo turn in unison with the Steering of the Drive Wheels...

    It will be fun, I Promise...
  • TtailspinTtailspin Posts: 1,326
    edited 2010-09-05 21:40
    !SUCCESS!

    This stuff is so easy...it's hard...

    Thank you agfa, that was most kind of You for the "IF" suggestion..

    Try this on for size...
Sign In or Register to comment.