![]() |
Re: Programming tricks (and former trade secrets)
Quote:
Quote:
Code:
#define CALAXIS1 p1_yBasically you just have to play with the calibration trimmers until both red and green LEDs are ON for that axis. Might be tough at first but you will get the touch. All 8 LEDs ON = "Calibrated and ready to go". :) |
Re: Programming tricks (and former trade secrets)
Thanks for the note, this is a very good point...
We see the same behavior whenever we reset the RC. Fortunately, our offsets are small, so the bot doesn't go nuts. Thanks, Jim |
Re: Programming tricks (and former trade secrets)
Quote:
Some will recognize Kevin's interrupt framework, but everything else is different. Here's the relevant portion of the interrupt routine: Code:
Initialization: Code:
unsigned char i, j;Code:
#define NUM_TACH 4 |
Re: Programming tricks (and former trade secrets)
Quote:
I also came up with an interesting result when I figured how long it took to maintain the ring buffer. With as many as ten entries, it turned out to be faster to move all of the values every time than to index through an array. Array operations are convenient and make for easier coding in many cases, but they can be remarkably slow. |
Re: Programming tricks (and former trade secrets)
we worked on writing a new scripting language for autonomous mode.
so easy to write new logic I had mechanical people writing some stuff. |
Re: Programming tricks (and former trade secrets)
Quote:
I don't doubt that individual moves would be faster as it avoids one or more multiply operations to compute the array index. Although the interrupt routines use an arrayed variable to store the tach counts, the use of an absolute index allows the compiler and linker to resolve this to a fixed memory location at build time. The overall simplification of Kevin's code by reworking the logic to remove direction sensing as well as the overhead of function calls helps reduce the CPU loading where the impact is the greatest. My primary point in sharing the idea was to provide a simpler example of how a velocity only interrupt could work, and to introduce the idea of using a sliding window for data values to improve resolution. I chose to use arrayed variables in the 26ms loop for the tach code as well as all of the remaining PID code just to help with readability and to make it easy to change the size of the ring buffer, or add/delete motors. Certainly if the CPU didn't have any idle time left, the arrays are one of the first things I'd go after. |
Re: Programming tricks (and former trade secrets)
[quote=The Lucas;585702]It only uses the LEDs while the bot is disabled, since it should be calibrated before enabling. You are free to use the LEDs as you would during the match, just put that code in the else statement. Just make sure your LEDs are set every loop to avoid confusing the drivers with stray lights.[quote]
Now, why didn't I think of that? Thanks for the tip. |
Re: Programming tricks (and former trade secrets)
Quote:
It only served to reinforce my motto "when in doubt, add parenthesis". It appears that the compiler gives greater precedence to * than it does to ? So what the code was doing was this: output = ((input * input / 127) * (input > 0)) ? 1 : -1; not this: output = (input * input / 127) * ((input > 0) ? 1 : -1); As written, the code only returned +/- 1. With parenthesis added as in the second example, the code did what was intended. The other cool by-product of this code is that it adds in a small dead-band to the joystick. Any offset less than 13 returns a zero after interger math truncation. |
Re: Programming tricks (and former trade secrets)
Quote:
Parenthesis is, of course, the correct way to create the desired association, and when using the ternary operator is a good habit to adopt. |
Re: Programming tricks (and former trade secrets)
Thanks for the notes!
I'm coming from a PHP background--all math is given equal precedence in PHP; you use parenthesis to emphasize certain points to be performed first--also, all expressions are evaluated before math is performed. Also, one thing you must be careful of when using this particular phrase is that the input variable must either be an int or typecast to an int before performing math. If "input" is a char, the math will overflow the size of the type, creating... shall we say, "undesirable" results. :P |
Re: Programming tricks (and former trade secrets)
Quote:
If the compiler is really standards compliant, objects or expressions of rank less than int (such as unsigned char) are converted to int (if int can represent all values of the original type) or unsigned int (otherwise); this is known as integer promotion. In the case of multiplying two unsigned chars, the the product of two values of unsigned type will be reduced according to the range of values for that type. This is an area where compiler's behavior will sometimes vary, especially those targeted towards 8 bit native platforms (such as the PIC18) where math with 8 bit variables is not always evaluated as an integer (which in this case is 16 bits). Not all compilers correctly perform integer promotion, and I've only run across one that did not behave any better when type casts were applied. In the case of the PIC18 compiler it does understand integer promotions, however the default behavior is to not do it. The C compiler documentation covers this in section 2.7 (ISO DIVERGENCES). |
Re: Programming tricks (and former trade secrets)
Well, we've got some good things going on. I guess everyone else was either hurrying or something with their programming, because we managed to play quite a lot of Counter-Strike and still have a perfectly functional robot heh.
|
Re: Programming tricks (and former trade secrets)
*to the tune of California Dreamin'*
CCPs make me happy... when the skys are grey... when i have the pwm blues... on a winter's day... update rate ga-lore... when the skys are grey-hey.... :cool: keep on dreamin... and good luck in Rack N' Roll! (by the way, low freq SDAR, team 1024's pet project, autonomous mode? we'll find out... *hint hint*) -q |
Re: Programming tricks (and former trade secrets)
Our drive code was such that 3/54 teams approached us specifically asking how we get such fine control of our robot.
I know this is a lot of code, and it's not very advanced, but man does it work well. Code:
int driveScaleFactor = 3;I will eventually post code that uses PD control with encoders to drive in a straight line autonomously. |
Re: Programming tricks (and former trade secrets)
We wrote our own sin() function.
It takes a degree measure in in "funnys", where there are 40 "funnys" per circle. We then directly map that angle to the table after correcting the sign of the number. We are using this to implement a feed forward controller with our PID controller. We will be adding in a function on Thursday that will take 2 angles and some other various data in from our double jointed arm, and output the torque that is being experienced on the "shoulder" joint and implement that into the PID controller for the shoulder. I also wrote our drive code so that the steering wheel we use specifies the difference in motor power between the left and the right wheels. This even works when the throttle is full forward. The code calculates it out so that even though it would like to run one motor at over full power, it lowers the other motor's power further instead to retain this difference in power. I like the reduced sensitivity code that I saw earlier. I think that I am going to implement a version of that using one of the buttons on our steering wheel to turn the mode on or off. Our sin(x) function: Code:
static const int8 sin_table[] = {0, 20, 39, 58, 75, 90, 103, 113, 121, 125, 127}; |
| All times are GMT -5. The time now is 18:06. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi