Subtracting and adding servo value

What I want to do is make Btn5U on the controller cause the servo to go up by 25. Also for Btn5D to mmake the value go down by 25. I’m using ROBOTC but all I need is some pseudocode to push me in the right direction.

EDIT: I figured it out

	

bool Btn5UWasPressed = false;
bool Btn5DWasPressed = false;
int ServoValue = 0;
	
	while(true)
	{

		if(vexRT[Btn5U] && !Btn5UWasPressed)
		{
			ServoValue = ServoValue + 25;
			Btn5UWasPressed = true;
		}
		
		else if (!vexRT[Btn5U])
		{
			Btn5UWasPressed = false;
}
		
		if(vexRT[Btn5D] && !Btn5DWasPressed)
		{
			ServoValue = ServoValue - 25;
			Btn5DWasPressed = true;
		}

		else if(!vexRT[Btn5D])
		{
			Btn5DWasPressed = false;
}
		motor[Servo] = ServoValue;
}

It works consistently according to the ROBOTC debugger however in real life not so much. But I think at this point it’s not a programming issue.

I’m guessing you might want to cap your values at 127 and -127. Also, I’ve heard that the motor response to input values is not linear, especially once you exceed a value of 100. For example, I’ve heard an input of 125 does not really provide 25% more energy than an input of 100.

This is certainly true with motors (on ports 2 through 9, ports 1 & 10 work correctly) and may be true for servos, never tried those. I can find the post with the detailed explanation if anyone wants the details.

That’s interesting about the different ports providing different performances that way. And, yes, if you can find the post with the details about the non-linear performance of motors, that would be much appreciated. I found the discussion about the old 269 motors but I was wondering if anyone had tested the 393’s.

Are Vex servos that much different from the Vex motors? I had always presumed the Vex motors were just “continuous rotation” versions of the servos.

The “original” 3-wire motors were continuous rotation versions of a servo. The 269 and 393 motors are not really the same. The servo has the driver (the MC29 part) inside and it may behave differently from an MC29, ! don’t know.

The 393s would behave the same as the 269s (more or less). The headroom to the control signal is partly in the cortex, partly in the MC29. Here’s the old post I think you have probably already seen.
https://vexforum.com/t/cortex-motor-speed-testing/21687/1

Yes, that’s the one. I guess hooking up a 393 motor with an encoder wouldn’t be too hard to do and see how things behave for various inputs and loads. How come I don’t see these questions being answered as part of some Science Fair projects or something?

I guess we did compare 269 and 393 motors at one point in the past.
https://vexforum.com/showpost.php?p=310600&postcount=4

You may also be interested in this post about the (now discontinued) vex pro controller, it had almost linear control of the same motor.
https://vexforum.com/showpost.php?p=302050&postcount=1

Hey, thanks! This is great stuff. The situation is even worse than I had remembered. Essentially, the performance flat-lines after a motor control value of about 90. I wonder if that remains true when the motor is under load.

https://vexforum.com/attachment.php?attachmentid=6475&d=1342324103

Well it I don’t even to to have code to control a servo anymore. It’s not strong enough so we are just going to use a 323 motor and a potentiometer, which obviously will be controlled a bit differently than a servo.

That’s all a servo (well, a cheap one) is, a motor, a pot and some analog closed loop control.

Pretty sure he means 393 motor. :slight_smile: