Calibrate potentiometers?

Is there a way to calibrate my potentiometers attached to my Maestro 12?
I am seeing that the range goes only from 29-232 in the status tab of the MCC.
I am using a variable power source which I have adjusted (to 5.372V) to get the middle of the pot to be exactly mid range.
The pot is a 2.4k linear pot.
This is the code im using:

begin 1 get_position 4 times 4000 plus 0 servo repeat

I should clarify that when my Pot is at its lowest I want my servo to be at about 1050.
When the pot is at its max I want my servo at about 1950.
I need to have all the pot values in between the min and max to be scaled evenly

I believe the pot is restricted mechanically. It is embedded within an RC transmitter 2 axis control stick. Usually in the RC transmitter there is an option to calibrate the sticks/switches so that the computer knows what values to use in the formula to create the output value.

Im hoping that since I know my min and max values of my pot (29 & 232), I can modify my script to get the servo values I need.

________Min Values____Max Values
________Pot__Servo____Pot__Servo
Status___29___1115_____232__1920
Stack___115___4460_____918__7672

Hello.

It looks like you are using the example script from the “Using an analog input to control servos” heading of the “Example Scripts” section of the Maestro user’s guide. You might be able to fine-tune that script a little bit more (like you mention), but it looks like it should be doing very close to what you are asking for.

For example, when your potentiometer is at the lowest point, the value of 29 in the “Status” tab is read as about 116 in your script. After multiplying by 4 and adding 4000, you should end up with 4464 quarter microseconds (or 1116 microseconds). Similarly, a value of 232 for your upper limit results in a target of 7712 quarter microseconds (or 1928 microseconds).

By the way, the inputs on the Maestro are intended for 5V, so you should make sure that your potentiometer signal does not exceed 5V when it is at its maximum output.

-Brandon

Thanks for the reply Brandon.
I know my values are close, but I need them to go closer.
For my min values, when the pot goes to 29 I need my servo to go to 1050 or lower, and scaled evenly in between.
Similarly at the max when the pot reads 232 I need my servo to go to 1950 or more,and scaled evenly in between.
At the mid point I need my servo to read 1500.

You can find the values you need for fine-tuning your scaling factors by doing a little bit of algebra to find the equation for the line. For example, the 4 times 4000 plus values would create a line with a slope of 4 and a y-intercept of 4000. Using the two points you want as a reference, with some extra margin of safety, (y equals 4200 quarter microseconds when your potentiometer, x, reads 120 and y equals 7800 quarter microseconds when your potentiometer reads 920), you should get a slope close to 4.5 and a y-intercept of approximately 3660. However, since the Maestro does not have script commands for floating point algebra. you can use the following work-around to multiply the reading by 4.5:

begin
  1 get_position

  dup 4 times #duplicate the potentiometer reading then multiplies the duplicate by 4
  swap  #swap the duplicated (and multiplied) reading with the original reading
  2 divide plus #divide the original reading by 2 and add it to the duplicated reading
  
  3660 plus #add the y-intercept value

  0 servo
repeat

-Brandon

Do you have a specific formula to calculate the slope and y-intercept?
edit: I realised I just need to set the values out as a linear simultaneous equation and solve for x and y.

So if my slope ends up being 4.6, would my code look like this?

begin 1 get_position dup 4 times swap 10 divide 6 times plus #Is there a percentage command I can use here instead? 3660 plus 0 servo repeat

Instead of a 1 decimal slope of 4.6

use a 2 decimal slope of 4.65

Dividing by 100 to enable a slope with 2 decimals would end up being inaccurate as the answer to “100 divide” would be just rounded to the nearest whole number, when it goes to the stack.
Is there is a command to get the percentage of the top stack number?
It would allow me to use a slope with 2 decimals as it eliminates the “100 divide” step.
something like

begin 1 get_position dup 4 times swap 65 percent plus #Is there a command for "percent"? 3660 plus 0 servo repeat

In regards to serial communication, if I want to “get_position” from device number 2/channel 1, is the command as follows:

I got that from here: https://www.pololu.com/docs/0J40/5.e

or do I have to convert my device number “2” and channel number “1” to a hex format?
If so, how?

Does the number 2 = 0x2 in hex?
Does the number 1 = 0x1 in hex?

Your code for doing a single decimal would probably work fine. Please note that the when dividing integers like this, the results will get truncated. This is why dividing by 100 and multiplying by 65 (from your second example) is probably not as practical. There is no “percent” command in the Maestro scripting language; you can find all of the mathematical commands under the “Mathematical commands (unary)” and “Mathematical commands (binary)” headings in the “Command Reference” section of the Maestro controller’s user’s guide.

As far as your question about serial communication, the bytes you listed for the GET_POSITION command would work fine (e.g. you can mix hex and decimal bytes in the same command). For the two cases you gave, the conversion from decimal to hex is simple (1 in decimal is 0x01 in hex and 2 in decimal is 0x02 in hex). You should be able to find a lot of resources online for doing these conversions. For example, a quick Internet search led me to this “Binary to Decimal to Hexadecimal Converter” from Math is Fun.

-Brandon