PBP projects for R/C models


Closed Thread
Results 1 to 40 of 772

Hybrid View

  1. #1
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Ken, there are 2 issues that have not been addressed since the beginning of this project.

    1. The less serious of the 2 is your use of the hardware PWM module. R/C devices, such as servos and ESC's, expect a control pulse (typically 1-2mS) at about 50Hz. You can probably go lower to 30Hz or higher to about 100Hz and things should still work fine. However, a PIC16 with a 20MHz clock (which I believe you are using) will not go below 1220Hz (PR2=0xff). Even with an 8MHz clock the lowest is 488Hz (244Hz with a 4MHz click) and is still probably to high compared to the desired 50Hz.

    2. To get a closed loop control system to work correctly, you need more than a bunch of if-then-else statements. Ideally you want to use a PID controller. A proportional-integral-derivative controller (PID controller) is a generic loop feedback mechanism. It measures a process variable (e.g. temperature), and checks it against a desired set point (e.g. 100 degrees Celsius); it then attempts to adjust the process variable by changing a controller output (e.g. PWM signal to an electric heater) which will bring the process variable closer to the desired set point. Even a simple P (proportional only) controller would be much better than what you currently have.

  2. #2
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default Pid??

    I have been wondering whether I have a basic mistake in my feedback loop. I am measuring distance and adjusting rate of speed and rate of turn. Maybe I should be measuring rates not scalars

    This means differentiating. I would need to measure two distances a fixed time apart. Then do some subtraction. I do that a little bit in my code, when I include "oldrangeright" in my state machine, but since there is no consistency to my sample time...... Rate of turn is even less clear.

    Is this the PID flaw you are suggesting? What is the solution? What are the technical limitations? Will a 16F887 do the job? Do I need C code including appropriate libraries? I do not know how to start.

    Your comments about my PWM are true. I found what works by trial and error. To get 50hz would I need to install an outside oscillator? Might I somehow divide down the internal one?
    Ken

  3. #3
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default Upon further thought....

    I think you are telling me that I have not been using my PWM mechanism. In the case of turning I have defined STRAIGHT QuarterRIGHT, HalfRIGHT, RIGHT and the corresponding for LEFT. (I did not show you folks my definitions.) But I only use STRAIGHT, RIGHT and LEFT. That's bang-bang like a TOY level car. I could be doing much finer adjustments if I did a bit more arithmetic on my SONAR readings. GOOD IDEA. GOOD OBSERVATION. Presently I do comparisons in HEX. I really don't want to waste time translating to decimal.

    Thank you!!

    Ken

  4. #4
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default measuring velocity??

    I can not imagine a cheapo device that will measure closing rate.

    Can a robot know closing velocity other than by measuring distances at specified time intervals and divide? Anybody seen this done with PBP (or C or C++) on a PIC? Is this the reason I will have to upgrade to a 32MX460? I would love to see sample code.

    Ken

  5. #5
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Have you fixed the easier of your 2 issues yet? Expecting it to work correctly at 1220Hz when it is waiting for 50Hz may be a bit of a stretch. You can create a multi-channel, interrupt-driven, software PWM with a PIC16 and a 16-bit timer - such as TIMER1. If you don't know how to do that, then select a PIC18 and use DT's 2-CH Hardware Servo Driver (see CMS articles on the right of the HOME page). It is limited to only 2 channels but will work for your project for now.

    When you have that working correctly, then you can progress to the PID stuff which looks like this:
    Name:  TEST-6A.jpg
Views: 1536
Size:  41.8 KB

  6. #6
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rmteo View Post
    When you have that working correctly, then you can progress to the PID stuff which looks like this:
    Attachment 4944
    Hey RMTEO,

    Don't be shy about posting actual code. We would love to see your PBP example of the above.
    http://www.scalerobotics.com

  7. #7
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by scalerobotics View Post
    Hey RMTEO,

    Don't be shy about posting actual code. We would love to see your PBP example of the above.
    Hey SCALREOBOTICS,

    What made you think that I was going to do that in PBP? I do not think that PBP would be the way to go for Ken's situation but I would be happy to have you prove me wrong.

  8. #8
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Great point Bert.

    Ken, can you remind me again, what sonar sensor you are using? Parallax's sensor looks like it can do just about every 20ms. But not sure what it will do with echos that are further away. But I don't think you are using their sensor, so it probably has different specifications.

    Walter
    http://www.scalerobotics.com

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. PBP Extensions, What are they?
    By PJALM in forum PBP Extensions
    Replies: 9
    Last Post: - 28th September 2021, 11:26
  3. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 19:01
  4. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th December 2005, 23:30
  5. Making PBP code more modular
    By forgie in forum General
    Replies: 30
    Last Post: - 25th October 2005, 16:24

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts