|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Gyro PID User drive - How we did it
Quote:
Quote:
|
|
#2
|
|||
|
|||
|
Re: Gyro PID User drive - How we did it
one way you could improve your code is remove the floats since they are very expensive to the processor and replace them with a numerator and denominator. Then when doing your math you do everything for that portion and divide last.
ex. char Kp = 5; char kpDiv = 100; pTerm = (Kp * p_error) / KpDiv; You will lose the precision of having a floating point value in the end, but with PWM values I do not think that matters anyways also I am wondering why your errors are floats? Last edited by Render : 25-02-2007 at 23:08. |
|
#3
|
|||
|
|||
|
Re: Gyro PID User drive - How we did it
Alan,
I did sort of say we weren't using the I component by saying we were using P&D, but should have been a little more clear. I took a pass through the comments, but as usual missed a few that no longer matched up with the code. Odd that you have had issues with 255, we have always used it without issues. Don, The drive setup is a typical setup with one motor on each side (facing opposite directions) that power the drive wheels on that side. As the motors face opposite directions we need to do the inversion for (in our case) the right side as shown in the bottom of the PID_adjust() routine. // Invert the right output and put them to the wheels OUT_PWM_LM = left_out; OUT_PWM_RM = 255 - right_out; I definitely urge you to play with the gyro and this code and the other available examples for driving the robot. We hadn't used a gyro in previous years because I didn't understand them or PID routines, but dug into it this year and did some reading and the result has been great. Render, As I mentioned in the original post the code was not optimized for size or speed and we will get rid of the floats in future revisions. The errors were made floats so it didn't have to add code to convert from an integer to floating point before it made the calculations. Thanks all for the feedback! Adam |
|
#4
|
|||||
|
|||||
|
Re: Gyro PID User drive - How we did it
Quote:
Quote:
The communication protocol between OI and RC uses a pair of 255 (0xFF) characters to synchronize frames of data. Back in the pre-C days, it might have been possible to confuse it by setting adjacent pwm values to 255. My experience is with the 2004 and later control system, which refuses to report a pwm value greater than 254. I don't know whether the limit is enforced on the actual pwm output or if it's just the dashboard data coming back from the RC that won't go that high. |
|
#5
|
|||
|
|||
|
Re: Gyro PID User drive - How we did it
Tom,
I saw your post of your PID code, thanks! Reviewing this with my programming students will be a great learning exercise as we haven't covered structures yet. Alan, Thanks for the info on the max value of 254. Looks like we need to go through our code and make some changes. |
|
#6
|
|||
|
|||
|
Re: Gyro PID User drive - How we did it
That was Billy's from 1124. Either way, its a pretty good way to get into structures. It covers typedefs, local declarations, and pointers.
|
|
#7
|
|||||
|
|||||
|
Re: Gyro PID User drive - How we did it
Quote:
![]() |
|
#8
|
||||
|
||||
|
Re: Gyro PID User drive - How we did it
Quote:
The difference in output between 255 and 254 is not going to be noticeable, and Victors have a small center deadband, so both 127 and 128 are going to give you a "full off" from the Victor, so it really doesn't matter which way you do it. Just don't try to use 256 as your "full on" value. ![]() |
|
#9
|
|||
|
|||
|
Re: Gyro PID User drive - How we did it
Keep in mind that 2003 was a radically different RC than today's C-based controllers. The radio protocols changed as well in 2004, and so 255 doesn't have the stigma it used to. You may not see any difference between 255 and 254 in actual PWM output, but the only thing weird about 255 now is that 255+1 = 0.
|
|
#10
|
||||
|
||||
|
Re: Gyro PID User drive - How we did it
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| PID cmd_drive can't drive straight? | gnormhurst | Programming | 4 | 18-02-2005 01:54 |
| Drive Straight C Code using Encoders without PID? | Chris_Elston | Programming | 17 | 15-02-2005 23:41 |
| How many drive motors did you use (per side) this year? | Billfred | Motors | 19 | 16-10-2004 20:27 |
| How did YOU drive your team nuts these six weeks? | archiver | 2001 | 10 | 24-06-2002 01:13 |
| How did YOU drive your team nuts these past 6 weeks? | Jessica Boucher | Chit-Chat | 35 | 16-03-2002 01:04 |