Tare motor in PROS

Whenever you work with the position of a motor, you usually tare the motor at its current position so that position is set to be the zero position. However, I do not want to waste time in autonomous setting to that position and then taring (if thats a word) it.

My question is it possible to set a certain position like -227 to the zero position instead of setting the current position of the motor as the zero position?

You would reset your motor encoders during the Pre-auton phase

explain please
(20 char)

All you need to do is include an offset in any code that utilizes the position.

For example, instead of

if(position < 20)

you might do

if(position - 227 < 20)

This is certainly not the only way to accomplish the task, though.
1 Like

It sets the motor encoder position to 0 from -227 so it is what OP is asking is it not? Anyways I’m not sure what the command is in pros

To set the encoders to a value in C++ vexcode use:

:setRotation(double val, rotationUnits units);
1 Like

OP is asking to set the zero position to something other than the current position.

1 Like

Yes. https://pros.cs.purdue.edu/v5/api/cpp/motors.html#set-zero-position

4 Likes

isn’t there a typo in the PROS example code?

void autonomous() {
pros::Motor motor (1);
motor.move_absolute(100, 100); // Moves 100 units forward
motor.move_absolute(100, 100); // This does not cause a movement
motor.set_zero_position(80);
motor.move_absolute(100, 100); // Moves 120 units forward
}

if the line "motor.set_zero_position(80); " set the current encoder position as 80. Next line tell motor to move to absolute value of 100. Shouldn’t the motor only move 20 units forward?

There is a typo, but I don’t think it’s in the way you expected

  motor.move_absolute(100, 100); // at 100 (moves 100)
  motor.move_absolute(100, 100); // at 100 (moves 0)
  motor.set_zero_position(80);   // at 20
  motor.move_absolute(100, 100); // at 100 (moves 80)
2 Likes

means set the encoder position 80 units from current position as zero?

It sets the zero position, from which all other positions are measured, to 80 units. Not 80 relative to where you are now. Just 80 in the “global” reference frame.

2 Likes

So zero sets the specified position to zero and adjusts the current position relative to that (new current val = old current val - specified zero val).
And, tare sets both the zero position and current position to 0.

Is there any difference in the time it takes to perform these two operations? I would guess nothing noticeable but I could be wrong. Which would mean that @Barin suggestion would be the most efficient.

And, tare sets both the zero position and current position to 0.

No. set_zero_position sets the “zero position” (the position to which other positions are measured) to whatever value you give it. tare_position is the same as calling set_zero_position with the current position of the motor. Both of these operations make one call to the sdk: https://github.com/purduesigbots/pros/blob/ae9ecf4d61fb760a9ab2bae05022edd1a4cbc359/src/devices/vdml_motors.c#L210

3 Likes

hmm, well I guess I should have expected that considering its called “tare” and not reset.

So now I’m not clear on how that impacts get_position and get_raw_position? Is the following true? If not please fix so I can better understand.

  motor.move_absolute(100, 100); // at 100 (moves 100)
  motor.move_absolute(100, 100); // at 100 (moves 0)
  motor.set_zero_position(80);   // at 20
  motor.move_absolute(100, 100); // at 100 (moves 80)
  // 
  std::uint32_t now = pros::millis();
  std::cout << "position = " << motor.get_position()  // prints "position = 100"
  std::cout << "raw position =" << motor.get_raw_position(&now); // prints "raw position = 180"

@rbenasutti Thank you for your time.

Your comment for get_position is correct. Not sure what get_raw_position does, never used it, but your comment seems reasonable.

2 Likes