|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
That's the best description I could think of to describe this problem. I have the following code:
Code:
void Elbow_Targetize_PID(void) {
unsigned int current;
signed int error, output;
current = Get_Analog_Value(elbow_pot); // measure the elbow potentiometer
elbow_motor = 127; // just to be safe
// (elbow_target_abs is a global variable describing the goal state of the
// potentiometer. It is set up this way to make the elbow's usage roughly
// in line with that of the PWMs and such
error = ((signed int) elbow_target_abs) - ((signed int) current);
//yes, I know I'm cast-crazy...
output = (error >> 3); // quickly divide by 8
output = output * 2; // and multiply by two (I have no idea why I did this)
// kick the output out of the deadband
if (output < 0) output -= 7;
if (output > 0) output += 7;
// finally, assign the end result to the motor (it's backwards)
elbow_motor = (unsigned char) (127 - output);
// the output gets limited later by a safety function, though it occurs
// to me that I should do it in here to avoid problems
}
At any rate, the problem is in the bolded lines. They don't seem to be getting executed at all. I've checked it several times and it still doesn't seem to do it. Now, the elbow control works fine despite this, but it still worries me. I can only guess that those few lines are being "optimized" away for some reason by mcc18. I even put the same function into another development environment and tested it, and it worked as expected. What gives? I'm using Master Software 10 and mcc18 2.40 with MPLAB 7.00. Maybe I'm crazy. Could someone else try this function to see if the problem shows its hairy face? Last edited by Orborde : 18-04-2005 at 17:58. |
|
#2
|
|||||
|
|||||
|
Re: Weird Disappearing Commands
Quote:
I can spot several chances for errors in this code. First: >>3 works great for positive numbers, but will only give you headaches if the number you're shifting is negative. (I'm almost positive. I'll leave it as an exercise for the student to demonstrate yea or nay.)Second, if you're expecting the lines in questions to only do something when output is between -6 and +6 (as your comment seems to indicate that you might), you're wrong! Third, if output starts out between -6 and -1, it will first have 7 subtracted from it, and then immediately have 7 added back in! Do any of those sound like it might explain the behavior/symptom you're seeing? Last edited by Greg Ross : 18-04-2005 at 19:31. Reason: Just to comment that the pun was NOT intended. :) |
|
#3
|
||||
|
||||
|
Re: Weird Disappearing Commands
Quote:
Quote:
Quote:
Quote:
I'm sure I missed something, though. When I posted this, I had momentarily forgotten my motto, "No matter how irrational the problem seems, it's always your own dumb fault." Thanks for the help. Feel free argue with and make fun of me if my logic is fatally flawed. Last edited by Orborde : 18-04-2005 at 19:13. |
|
#4
|
|||||
|
|||||
|
Re: Weird Disappearing Commands
Quote:
|
|
#5
|
||||
|
||||
|
Re: Weird Disappearing Commands
Just for giggles, why not try changing the divided by 8 and multiply by 2 into a divide by four? It will probably be about the same, and even if it's not I don't think the nanoseconds will be noticable.
![]() P.S. Casts are good. I had at least 3 times where I'd test something for literal hours, only to find that my original code was fine. All I had to do was add casts for things which the compiler should have been able to easily handle on its own... ![]() |
|
#6
|
||||
|
||||
|
Re: Weird Disappearing Commands
Quote:
What I am getting at is that the speed controllers have a built in deadband of +/- 10, not 7, centered on 127. In other words, 7 doesn't quite kick you out of the deadband region. But expanding your numbers too far could lead to an unsafe/uncontrollable situation where it will never find a stationary position. Try increasing the value +/- 1 at a time. And, by the way, let us know how it turns out!!! |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can anyone create new commands? | Jakenan | Programming | 5 | 22-01-2005 21:38 |
| Autonomous Commands Promised in Kickoff | schenkin | Programming | 11 | 16-01-2005 08:58 |
| Weird Al | MattK | Chit-Chat | 7 | 10-11-2002 00:33 |
| Voice Activated commands | Amber H. | Technical Discussion | 40 | 03-11-2002 12:40 |
| the weird feeling.. | archiver | 2000 | 3 | 23-06-2002 23:08 |