V5 Controller Presets

Hey our team is trying to figure out controller presets so when we press a button on our controller it does that. Can anyone explain how that works and maybe show an example of how to do it. We are using vex coding studios c++.

By controller presets, do you mean the drive function on V5? Because when programming, there are no presets that I know of.

So what you want to do is have a function that will be run when you press a button, like ButtonUp on the controller. I am assuming your controller is configured as Controller1 in this example snippets…

void shootPreload() {
// write your code to shoot the preload
}

then in the main() part of your program BEFORE the while () loop you will want to register the button to execute the shootPreload function when pressed. Looks like:

// register the up button to shootPreload
Controller1.ButtonUp.pressed( shootPreload() );

done!

1 Like

Oh ok because ya what I’m trying to do is when a button is pushed it shoots the puncher and pulls it back so it is about to shoot.

see my response and if you have trouble, post your code…

Ok thanks for the answer.

So then I dont have to put anything in the while loop.

correct, you are registering the pressed event just once at the start of the program.

Oh ok thanks for the help.

When I put that code in like showed it gives me this complication error. What should I change.20190408_200316 20190408_200258

This would be the structure for the program:

// this is created by VCS graphical configuration                                
#include<robot-config.g>

void shootPreload() {
  // write your code to shoot the preload                                        
}

int main()
{
// register the up button to shootPreload                                        
  Controller1.ButtonUp.pressed( shootPreload() );

  while(1) {
    // all your code here                                                        
    vex::task::sleep(20);
  }
}

I am going to guess you are pretty new at this.

2 Likes

I am but I just put your code in and it wont run the puncher motor at all.20190409_075410|375x500

If you post your code we can probably help more. Preferably in a form where we can edit it. Cut and past in the text will be ok.

20190409_075410
Well here’s the code it is just a picture I can send you the full program later.

Do you see anything wrong with it

Your button pressed is not in the while loop, so it will not be called continuously. Not sure if that is what you’re trying to do or not though.

I don’t see any syntax errors or anything from a glance.

It should not be - it is registering the function to be called when the event happens “pressed”. You might be thinking of .pressing which is different.

Ah that makes sense now.

Do you think it should work or what do you think is wrong with it.

It’s entirely impossible to tell what might be wrong with it, as we can’t see everything that’s going on. That’s why lacsap asked you to copy and paste your code here so people could look at it. Sign into the VEX forum on the computer you’re coding on, copy and paste the code into a reply, highlight it all, and click the </> button to give it code formatting.

What’s blocking our view is all of the setVelocity and setMaxTorque commands at the top of main’s while loop that don’t actually need to be there. But even then, only ten lines of main is probably not enough to see all the substantive things you’re doing in there. Camera photos of monitors are almost never useful for diagnosing problems on a working computer.

1 Like