Bang Bang

Would I need high strength gears to handle bang bang code? Is it dependent on motors? What have you found is the best set up for an efficient bang bang? I am using a single flywheel (4 motors, geared 25:1 with high torque), some code of a bang bang controller would be helpful as well.

On the most basic level, bang bang is this:

if (flywheelSpeed > targetSpeed) {
    motor[flywheel] = 0;
} else if (flywheelSpeed <= targetSpeed) {
    motor[flywheel] = 127;
} 

Physically, your mechanism is different than every other mechanism, so I’d recommend testing it yourself!

But think about it, would you want your motors continually going between 0 and 127 :wink:

I’ve shattered gears before. I had a higher gear ratio, but it was not pleasant to fix. If you plan to do this, I would try 30 and 0, then 63 and 0, then 90 and 0, then 127 and 0, stopping if something bad happens.

It was just an example :slight_smile:

I know, I just don’t want anyone to try this lol :wink:

60 and 127 would be far safer :slight_smile:

That isn’t really correct…

The way our bang bang code works is that if it’s over, put it at the value we want, and If its under, then 127 and it works pretty well

"that"being 25 and 127?
And I’m having trouble finding that match video so you have a link?

Ok I see what you mean from those match videos :slight_smile:

I will change the values in ours tomorrow and see if it helps :slight_smile:

A cool bang bang program would go from zero to 127 as fast as safe then hold 127 until it gets close then uses a PID to get accurate. I’ll try this once I have time…

Well PID would already do this? If the error is absurdly large then P should be 127 anyway.

This is our team’s first flywheel velocity control attempt, and we do not have much experience with PID or bang bang code. We were wondering if anyone could take some time to review this code before we try it on our flywheel.

float barShotRPM = 2000 //Set RPM here for bar shots. Tune this!!!
void currentSpeed() { SensorValue[flywheelEncoder]*5 }
void flyMotorSpeed(int speed)
{ 
motor[port10] = speed;
motor[port1]= speed; 

}

if(currentSpeed <= barShotRPM)
{ 

flyMotorSpeed(120);

}elseif(currentSpeed > barshotRPM)
{
flyMotorSpeed(90);

}

Flywheel Specs:

  • 2 high speed motors
  • 84:36, 60:12 compound ratio (1:11.666)
  • STRICTLY bar shots
    -encoder is mounted on the 36 and 60 compound gear axle

Please excuse any syntax errors at the moment, as I’m still a novice programmer, but do add any input. The logic behind setting the acceleration speed at 120 was to keep a decent acceleration time, while keeping the motor stress down. We’re not sure if the next part will work, but the thought process was if the motors slowed down then the flywheel would slow down too. As I saw above, going from 127 to 0 would stress the motors, so I made the flywheel stall speed at 90. Hopefully my explanation was clear, but ask if you need clarification. Once again my team and I would appreciate any feedback.

I see a few issues that you might need to fix first:

  1. For the last two if statements, I see that you also have functions here, so those if statements will have to be in a task, probably the one for driver control.
  2. I see that you’re basing your velocity calculation for the bang-bang controller on the currentSpeed function. That’s good, but to do that you need the currentSpeed function to return a value. So, first, that “void” that precedes the function name is saying what kind of variable, if anything, the function returns. Since SensorValue[flywheelEncoder] is an integer, you’ll want the function declaration (the type + name of the function) to be

int currentSpeed()

. Then, on the inside of the function, you need to


return

encoder reading. To do this, just precede SensorValue with the word return.
3. For the bang-bang controller to work right, it needs to be based off of an estimate of your flywheel’s speed, which is usually done in RPM (revolutions per minute). The currentSpeed() function you have returns an encoder reading multiplied by 5. But as long as your flywheel keeps spinning, the encoder reading will keep going up, while the barshotRPM variable will remain at the same value the whole time. So more than likely, you’ll find that your velocity controller seemingly stops working after a very short period of time. To fix this, you need to change the way you calculate the velocity of your flywheel; see a thread like this one to see how to do this.

You’re off to a great start. So if you fix these few bugs (though more than likely, you’ll find a few more along the way - that’s okay!), I think you’ll find that your program works pretty well. And if you have any other questions, let me know.

Does anyone have any ideas of how to implement the Bang Bang code in the operator control using EasyC?

Basically the same only as SetMotor(, 0) or SetMotor(, 127)

But then in operator control how do you connect that control to a certain button on the controller?

Speed Controls typically run at all times. You could call it as a function or simply have it in the main code.

So is there any way that you could put 2 set speeds on easy c? (Like one for bar shots and one for half court)
And does that mean that the flywheel never stops?