You would have the target speed change. Use the buttons to set a variable value.
Here is some example code of what I would use. You can really just ignore the power level adjustments that the code makes with a bang-bang controller. This is on a robot that uses PID adjustment instead, so I want the initial reading as close as possible to what it should be.
if (GetTimer(1)>100) {
if (GetJoystickDigital(1, 8, 2)==1) {
SetMotor(5, 0);
SetMotor(6, 0);
PresetTimer(1, 0);
currentMotorLevel = 0;
}
else if (GetJoystickDigital(1, 8, 3)==1) {
currentMotorLevel = barConstant;
SetMotor(5, currentMotorLevel*Pow(currentBatteryLevel, 2)/Pow(8050, 2));
SetMotor(6, currentMotorLevel*Pow(currentBatteryLevel, 2)/Pow(8050, 2));
PresetTimer(1, 0);
}
else if (GetJoystickDigital(1, 8, 1)==1) {
currentMotorLevel = halfFieldConstant;
SetMotor(5, currentMotorLevel*Pow(currentBatteryLevel, 2)/Pow(8050, 2));
SetMotor(6, currentMotorLevel*Pow(currentBatteryLevel, 2)/Pow(8050, 2));
PresetTimer(1, 0);
}
else if (GetJoystickDigital(1, 8, 4)==1) {
currentMotorLevel = fullFieldConstant;
SetMotor(5, currentMotorLevel*Pow(currentBatteryLevel, 2)/Pow(8050, 2));
SetMotor(6, currentMotorLevel*Pow(currentBatteryLevel, 2)/Pow(8050, 2));
PresetTimer(1, 0);
}
else if (GetJoystickDigital(1, 7, 2)==1) {
currentMotorLevel += 5;
SetMotor(5, currentMotorLevel*Pow(currentBatteryLevel, 2)/Pow(8050, 2));
SetMotor(6, currentMotorLevel*Pow(currentBatteryLevel, 2)/Pow(8050, 2));
PresetTimer(1, 0);
}
else if (GetJoystickDigital(1, 7, 3)==1) {
currentMotorLevel += 1;
SetMotor(5, currentMotorLevel*Pow(currentBatteryLevel, 2)/Pow(8050, 2));
SetMotor(6, currentMotorLevel*Pow(currentBatteryLevel, 2)/Pow(8050, 2));
PresetTimer(1, 0);
}
else if (GetJoystickDigital(1, 7, 4)==1) {
currentMotorLevel -= 5;
SetMotor(5, currentMotorLevel*Pow(currentBatteryLevel, 2)/Pow(8050, 2));
SetMotor(6, currentMotorLevel*Pow(currentBatteryLevel, 2)/Pow(8050, 2));
PresetTimer(1, 0);
}
else if (GetJoystickDigital(1, 7, 1)==1) {
currentMotorLevel -= 1;
SetMotor(5, currentMotorLevel*Pow(currentBatteryLevel, 2)/Pow(8050, 2));
SetMotor(6, currentMotorLevel*Pow(currentBatteryLevel, 2)/Pow(8050, 2));
PresetTimer(1, 0);
}
}
if (GetIntegratedMotorEncoderSpeed(5)>yourConstant*currentMotorLevel/fullFieldConstant) {
SetMotor(5, 0);
SetMotor(6, 0);
}
else {
SetMotor(5, 127);
SetMotor(6, 127);
}
Do you happen to have an example from easy c?
That is easyc
Oh okay. I couldn’t tell without the blocks. Does this work with shaft encoders?
Sort of. Here is what I would use for the end:
if (GetTimer(2)>50) {
if (GetQuadEncoder(, )>yourConstant*currentMotorLevel/fullFieldConstant) {
SetMotor(, 0);
else {
SetMotor(, 127);
}
PresetTimer(2, 0);
PresetQuadEncoder(, , 0);
}
It is not possible to run it quite as quickly because there is no get speed function from the quad encoders, but this will still run every 50 milliseconds, so it is pretty quick. You can try messing with the value of the timer to see how low of a value will work. If set too low, then it will not be very accurate.
What is the actual job for the various timers you used?
Sorry for all the questions. Ive just been going through various tests with my own code and it hasn’t been too well
The purpose of the timers in general is to add a wait command to part of the program. This lets part of the program only run every so often while others are (almost) instantaneous. The specific reason for the first timer is that I only want to change the shooter speed every 100 ms. Button presses take time, so if I test for button press every time through the loop, the variable could increment multiple times per time I press the button. The second timer is to allow the encoder to count up a small amount to record a difference. This gives a distance and a time allowing speed to be calculated.
I actually just switched to the IME’s altogether and it made things a lot easier. I did my program a bit different from your suggestion but it seems to work well. Would making the powers like 40 to 127 be too hard on the motors for bar shots?
It isn’t that bad, I wouldn’t go under 30 for the sake of your motors but it’s more of a test and see kind of thing
I just put it at 35 just to be safe. We are running it at 1675 RPMs