I just made the switch to using two controllers the other day, and I’ve noticed a few issues that have arisen as a result. When using one controller, it was easy to hit the button to open the claw on our robot and then back up away from a cube or skyrise piece as the claw closed (it is set to send about 20 units of power or whatever you call it to the claw always to help it grip heavier things), although now that one controller is doing the claw opening and another is doing the backing up, We’ll need to be able to keep the claw open while the other driver reacts and drives backwards. I currently have all of the commands entered as “else if” functions, and it doesn’t allow the two controllers to send two commands at once, even if they are pertaining to different motors.
How should I edit the programming to allow for multiple commands at once? I can post the current code tomorrow sometime if that would be helpful too.
You need to create separate tasks. One does the driving and one does the claw and other stuff. Assuming its robotc, you can create a task just like the user or main one. Then you can have StartTask(name of other task) in the user one.
That looks like a really good option. Would I be able to do all of that in the same task or does it need a new Task above each if statement?
Sorry if that’s a dumb question, but my only knowledge of C is from trial and error and looking off of the awful code that our team had last year…:rolleyes:
One can defend for Easy C, but that cannot change the fact that currently easy c cannot multitask… Multitasking makes your loops significantly neater. You first declare a task, then use startTask(); and stopTask(); to control them.
I forgot to mention this, but no, I’m not using Easy C. A copy of RobotC came with the Vex package that we got and it seems like that is the best option anyways.
It seems to be working well, even if it isn’t the neatest way of going about things. I’m just hoping to have it working by Saturday for our next competition.
So the key to the whole multiple loops thing is to have multiple “while” components? I tried just substituting some of the “else if” commands with “if” commands and it caused all kinds of weird things to happen. The motors switched on and off rapidly and it had kind of a sputtering effect.
On the other hand, it wouldn’t let me separate each controller’s code into its own “while(true) loop”
I’d hate to ask any of you to write out too much code because I’m a complete coding noob, but if I could just get an example of how I should edit the current program to give each controller its own “loop”, whatever that is, and not cause it to sputter and generally mess up.
sends the value 127 to the four motors and then exits, it might just as well (and should) be a function. For a task to be useful it needs to block for some reason, for example.
Alright so I’m totally stuck here. I tried putting each thing in their own tasks (arm lifts in one loop, wheel movements in another, etc.) but nothing worked. I tried putting each in its own while(true) loop, and that only ran the first program. I tried making each movement be under its own if statement as opposed to an else if like they had been, but that didn’t work.
How exactly am I supposed to do this? I get that there is a huge debate over whether or not to use Easy C and the deep philosophical junk behind whether to “multitask” or not, whatever that means, but I’m just a programming noob looking for some help understanding what I’m even supposed to type into the program before our team’s competition tomorrow.
Is it something like:
task usercontrol ()
{
if (vexRT[Btn5D] == 1)
//motor stuffs blah blah blah
else if (vexRT[Btn5U] == 1)
//blah blah blah
else
blah blah blah
}
task something else however that works ()
{
//if,else if, else, all that good stuff
}
I can’t find any resources on what exactly i’m supposed to do here and I have no more ideas on what to do. Any useful help would be appreciated.
I wasn’t thinking this morning, sorry. You are correct.
When Doinig User control, I think that it would be far easier and save some CPU to do something more like this and put all of the stuff in a big while loop in the user control function:
task usercontrol() {
while(1){
if (vexRT[Btn6D] == 1) {
motor[leftSpitMotor] = -127;
}
else if (vexRT[Btn6U] == 1) {
motor[leftSpitMotor] = 127;
}
else {
motor [leftSpitMotor] = 0;
}
if (vexRT[Btn5D] == 1) {
motor[leftLift] = 20; // lower main lift arm
motor[rightLift] = -20;
}
else if (vexRT[Btn5U] == 1) {
motor[leftLift] = -70; // raise main lift arm
motor[rightLift] = 70;
}
else {
motor[leftLift] = 0;
motor[rightLift] = 0;
}
}
}