Hello, so I am trying to have our robot fly-wheels spin off number of revolutions instead of motor power. So I want a code to…
When I hit a button it starts the motors, then the optical quad encoder counts how many revolutions the motors/wheels are spinning.
Then I want the motors/wheel to spin at a certain revolution so if the optical quad encoder reads the revolutions being too high then it slows the motor speed by one or if its too low it speeds up the motor speed by one.
motorrev = GetQuadEncoder (1 . 2);
if ( motorrev > 100 )
{
motorSpd1 = moorSpd1 - 1;
}
else if ( motorrev < 100 )
{
motorSpd1 = motorSpd1 + 1;
}
speedone + GetJoystickDigital (1.8.2);
if ( speedone == 1 )
{
if ( motoron == 0)
{
SetMotor (8.motorSpd1);
SetMotor (9.motorSpd1);
motoron = 1;
}
else if ( motoron == 1)
{
SetMotor (9.0);
SetMotor (8.0);
motoron = 0;
}
}
Here is a sample of my code that I have so far. So right now when I push the button on the joystick it doesn’t run anything. I believe its because the motors are set to run the variable but even if i set the variable to something it doesn’t run. Also don’t worry if the code isn’t right with the spaces or way it is written, I just had to copy it from easy c and i couldn’t tell if there were spaces or what the right punctuation was some times.
Any help would be much appreciated. Also if you have any questions about anything don’t be afraid to ask, I am not very good at explaining things.
Thanks,
Legobrickter
I’m afraid I don’t know EasyC, but one question I’m sure you’ll be asked: on what shaft have you mounted your optical encoder? I’m not sure, but I think kids have complained that optical encoders connected directly to flywheels can’t count fast enough, at least not for full court shots. And maybe some of them simply burn up.
You might want to look into using IMEs, integrated motor encoders, if you can.
One system that might be possible, if you’re really good at programing: try using a PID control. Perhaps google “EasyC PID flywheels” and have a look at this link:
https://vexforum.com/t/simple-pid-for-easyc-and-convex/28399/1
So we do have it mounted to the fly-wheel shaft but we will not be shooting it from the back but from right in front of the goal. So I do not know if it would be going too fast to burn it out or for it not be able to read it. Also i do know a little code or at least understand it. So if you know code that would work go ahead and write it out.
Okay so this code is all running inside a while loop right?
speedone + GetJoystickDigital (1.8.2);
Doesn’t really do anything. I think you are trying to set the variable to be equal to GetJoystickDigital.
Then your
if ( speedone == 1 )
{
if ( motoron == 0)
{
SetMotor (8.motorSpd1);
SetMotor (9.motorSpd1);
motoron = 1;
}
else if ( motoron == 1)
{
SetMotor (9.0);
SetMotor (8.0);
motoron = 0;
}
}
Will turn the motors on and off incredibly quickly as long as the button is pressed. This one I’m not quite sure what your goal is.
And then obviously the quad encoder will return it’s total Ticks rather than the Ticks in some unit time so this won’t really work for velocity control like you seem to want. I would suggest reading about TBH or velocity PID. What you are doing is pretty similar to a velocity P loop. The only difference is P loop says if you are really far from the goal speed increase speed by a lot and if your really close only increase a little.
In that case, is speed precision really all that necessary? Can you just have one button that increases your motor speed and another than decreases motor speed each time it is pressed? When you are that close to your goal, I doubt you need to worry about speed control very much.