Flywheel Velocity Control

Hello everyone. I’m requesting assistance with EasyC V4 for Cortex. I’m quite new to programming (usually the builder/driver), and need some help. I’ve decided to build a flywheel, but need to know a few things first. Is it possible to make a channel on the joystick do multiple things? For instance, in driver control, if Ch5 But1 is pressed, one operation performs, and if Ch5 But2 is pressed, another unrelated operation performs. Also, is it possible to turn on and off the VEX indicators when certain criteria are met, or when a button is pressed? Finally, I know nothing about velocity control for flywheels. I’ve never used any sensor other than a limit switch (I’m a pretty analog guy). If someone could please help me with any of these things, it would be greatly appreciated. I’ve tried to search for answers, but all I found were posts where people quoted robotc or other programs, and said to put that in EasyC. I can’t really understand that stuff, and I’d like to know what I’m coding, instead of just copying and pasting into EasyC (also something I don’t know how to do). Thanks for your time!

Now firstly I don’t use easyC, so instead of posting robotC code i’m just going to post pseudo-type code with some explanations.

Okay Firstly you could achieve this by having a variable that holds what set of commands to run when you move the Joystick. Then change the variable depending on what button you press (and we place all of this in our main loop).


while(true)
{
	int JoystickCommands = 0;
	if( Button 1 is pressed )
	{
		JoystickCommands = 0;
	}
	else if( Button 2 is pressed )
	{
		JoystickCommands = 1;
	}

Then in the loop we run a different set of commands depending on the value of the variable.


if( JoystickCommands == 0 )
{
	// Do your first set of controller commands here
	// motor 1 = Joystick Channel 1
}
else if( JoystickCommands = 1 )
{
	// Do your second set of controller commands here
}

Their may be a few issues with this code, but it is provided as an example. Feel free to ask questions :stuck_out_tongue:

If you are referring to the lights on the cortex I do not believe so. You can however hook up vex LED’s to your cortex and toggle them. You put them in your digital ports and toggle them using a digital output block.

That code does make sense, and I think I may be able to implement that in EasyC. And yes, I was referring to the VEX LED’s, thank you. I’m assuming I can y-cable four of these together to work on a single port and act as one large indicator? I only know of the y-cable rule on motors.
Thanks for your reply!

I think it is legal. I asked this near the beginning of the season.
https://vexforum.com/t/answered-is-is-legal-to-y-off-leds/29708/1
That post says two are legal, I am not sure about connecting four.

There is another one here that says it is legal to do four:
https://vexforum.com/showthread.php?p=327310?path=/user/smith/vft/showthread.php
But it is from 2013.

Cool, thanks! If I can figure out some kind of velocity control for the flywheel, I should be good to go. I’ve researched PID, and I think I understand how to implement it, but I’m still not sure how to tune it in EasyC, or even exactly what’s going on when it works.

PID is a little tricky, but there have been quite a few threads on it on this forum this season that you can look up. I would suggest starting with this thread as a reference: https://vexforum.com/t/flywheel-velocity-control/29892/1

If you decide to implement PID, start with just the P part (each time through the loop, change the motor power by an amount proportional to the difference between the current speed and the target). It will be much easier to program things that way, and it will still work ok. Then work up to building PID.