Recently I have been doing some relatively advanced math for my Vex robot (some isn’t that hard, some is a little more complicated), and every time I do, I make sure to test out the equations both manually (with a calculator), and in simulation (code them into a computer program and run them with test values on my computer). Once I get them working perfectly, I put them back into the Vex program, check everything out to make sure it’ll theoretically work, build it, load it, and bam, it doesn’t.
These are not mathematical miscalculations, all the math checks out. Neither are they variable overflows, I’m using variables that are plenty large for the application, and type casting them where necessary. These are instances where something just doesn’t work on the controller, and I can’t figure out what.
Specifically, the most recent ones have been for my holonomic drive program. I’ve had a holonomic control program working for a while, but recently I added in a scaling algorithm to make the joystick map to the speed and angle of the robot more closely. Basically, the individual wheel speed equations put the wheels at full tilt going forward/backward or left/right, but on the diagonals, there was a limited circle on the joystick you could move around before the equations overflowed the wheel speed variables, so I just capped them. This algorithm removed the need for capping and just scaled everything down to the wheel that was most out of range. In simulation.
In practice, if a wheel value gets out of range, all 4 wheels just stop.
Also, I tried halving the speed of an arm control motor by feeding it ((value-127)/2)+127 (so you can drive the motor slowly with a digital channel). It works great, but only in one direction. If you hit one button, the motor moves in one direction. If you hit the other button, the motor moves in the same direction as before.
Are these compiler errors, firmware errors, or PIC errors? I am, of course, always open to the idea that it’s user error, as it so commonly is, but I’ve checked all of these systems multiple times, and by all rights, it looks as if there’s nothing wrong except the fact that it doesn’t work. I’ve included my most recent program for reference (written in WPILib, the library used in EasyC). Feel free to criticize it all you want, I know my code isn’t pretty.
*As a note, in the code, I use the “~” character to invert unsigned character values. It is a bitwise operand that flips the value of all of the bits in the byte. It is equivalent to subtracting the value from 255.
DinoBot.c (3.78 KB)