![]() ![]() The more time that is taken for calculating things, the more the joystick will have a rubber-band feel to it, and I don't want that. Running on a pair of CAN-bus nodes, these integer calculations (not just curving for the 2 axes, but deadband, speedpot range setting and different scaling for forward and reverse as well) are still using substantially more time than the CAN messaging, or the rest of loop () for that matter. As I can't move a joystick with anywhere near that precision, I figure that this is more than good enough, and if one of these five curves doesn't give me the right feel I can always try another combination of original and squared (or cubed if need be, but I highly doubt that). The results of these integer manipulations are quite close (better than 1% at all points) to the curves shown in the graph for the exponents shown in the graph legend. (2) making different linear combinations of the straight analog value and the squared value: (1) taking the analog value and squaring it (using long as the number can get pretty big) ![]() In the stuff I posted, the four curves are generated by: Again, for joystick response, the thing we want is to get the right "feel" and that's something we're going to have to find out by trial and error. Same for things like polynomial curve fitting - computation intensive and overkill as well unless you want to precisely fit a curve who's characteristics you already know. For a real-time application, such as modifying joystick response, that may not be the best choice. That is a fine way to create an exponential curve, if you can afford the time and memory it takes to do floating point calculations. It's probably not the most efficient code for this, so any suggestions would, of course, be welcome. The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords. (6) re-map Throttle and Steering in accord with a Speedpot connected to third analog input pin.Īs the results of these calculations are fed into a CANbus network, there are probably some lines of code that refer to sending CAN messages, and I have not included the #define statements or variable declarations that precede all of this, but this does illustrate one way that one can get curving and scaling and so on using entirely integer arithmetic. (5) re-map the throttle axis to a new when going in reverse, and re-map the steering axis, with different steering sensitivities when going forward or revers. The result to this point is illustrated in the attached graph. (4) applies five levels of scaling ranging from linear to squared. (3) maps the voltage to a -1000 to +1000 scale (distinguishing between forward/reverse or left/right). (2) establishes a deadband as no joystick will perfectly self-center. (1) reduce output to 0 for voltages 4.95 V as that indicates a broken or shorted lead or internal joystick failure. ![]() Fractional remainders are truncated, and are not rounded or averaged.Attached are some procedures, from a much larger sketch, that I've used to scale and curve the outputs of a 2-axis Hall-effect sensor joystick whose normal outputs run from 0.05V to 4.95 V (assuming 5V reference source). The map() function uses integer math so will not generate fractions, when the math might indicate that it should do so. The function also handles negative numbers well, so that this example Note that the "lower bounds" of either range may be larger or smaller than the "upper bounds" so the map() function may be used to reverse a range of numbers, for example The constrain() function may be used either before or after this function, if limits to the ranges are desired. That is, a value of fromLow would get mapped to toLow, a value of fromHigh to toHigh, values in-between to values in-between, etc.ĭoes not constrain values to within the range, because out-of-range values are sometimes intended and useful. Re-maps a number from one range to another. Map(value, fromLow, fromHigh, toLow, toHigh) ![]() Here is my Arduino code using the map function, is there a function in mikroC32 like this? ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |