Okay, so I’ve messed around with the Vexcode IQ blocks a lot, and no matter what I try, I can’t seem to get the arm motor to be manually controlled by one button and have another set it to an automatic height. I’ve tried the ‘When button __ pushed’ block for one of the buttons we currently aren’t using on our remote, and nothing happens when the said button is pushed. So, I was wondering if it was even possible to have two separate buttons (i.e. f up and down and r up and down) to control one motor.
This is pretty easy to do in blocks! Can you post what you have so far?
Following because my students have a similar problem.
You can’t mix the controller setup with other commands.
Do something like this for moving the motor up (I think you had Lup). and duplicate it for moving ii down.
This will effectively have the program ignore the motor when it isn’t being used, allowing the F commands you have to run.
You can do this with both Vex code and VCS. You can assign one motor to 2 buttons . The thing is, this will create unwanted bugs so it is best to assign one motor to one button or 2 + if you would like to control an entire system with a signle button.
Is it that the “WHEN” works where “IF/THEN” will not? My students are using 2 “IF/THEN” blocks to control one motor and it’s not working. If the solution is the “WHEN” command, can you please help me understand why, so I can in turn explain it to my students?
“When XYZ” hat blocks are what we call hardware events - basically, that stack of code is executed when the specific event occurs (such as a button being pressed).
The If/Else logic would need to be within some kind of loop to be constantly evaluated to control motors based on button presses.
Thank you so much. I’ll have them build the code using “WHEN PRESSED” and see if it works. Just have to wait until practice on Tuesday. I hate waiting
Here is one of their attempts with IF/THEN statements that did not work.
We will try swapping all the blocks using buttons to WHEN PRESSED but won’t be able to try it until Tuesday
So we tried that, and it didn’t work. The arm movements are so choppy.
Did you try the If/Then in a Forever Loop or the When Pressed approach?
Thanks
You may want to add a wait (maybe 50ms) after the motor movement. We’ve seen that behavior on teleop when you want to press a button to move an arm without a wait.
So my girls are still not having success with this. They’ve also asked other teams for some input and discovered other teams have tried and have given up.
For those just joining in - my team has built a robot with a 2 motor base with tank drive set up in the set up area. It has a 1 motor 4 bar on the front and a 1 motor elevator on the back.
They have a reliable program to score the green cube son the low towers. They wanted to run the same program when a button is pushed in the controller during driver control and teamwork. They first tried a series of IF/THE/ELSE and couldn’t get it to work, They then tried using a series of WHEN hats and it still doesn’t work. All it would do is drive forward. No reverse, no turn, no lifting either the 4 bar or elevator, nothing. Here is there code…
The first part, setting all the parameters
Then, controlling the 4 Bar
Then controlling the elevator
And finally their few lines to score the green cube
(please ignore that last line of reversing… they have since corrected the difference in UoM and the distance)
Any help would be greatly appreciated.
@ChrisR246 I’m looking at the first screen shot, and I’m seeing that only the set velocities and motor hold commands are inside the forever loop. Is that correct? If so, then it’ll never get to your When Button Pressed Commands down below. You will nee to put the When Button Commands inside the forever loop right after the last motor hold command, so they can be executed.
OH! We completely misunderstood that! We thought they just sat out there all independent. Thank you. We will try that.
Sorry, @ChrisR246. Bit of correction. Not as familiar with VexIQ Code Blocks as I am with RobotC text.
Forever loops will require if/then else statements instead of the When commands. Looking at your screenshots again, another option is to just get rid of the forever loop (but keep the set commands for velocity and brake mode) as the only things there are your declarative type of commands. Those only need to be done once. So, if you get rid of the forever loop, it should execute the set commands once then immediately go into mode of listening fo the When commands.
Thank you!
So, by way of explaining it to my students, is it accurate to say that the computer looks at WHEN STARTED first. In this case it sees a FOREVER Loop immediately, its begins executing that loop and just never leaves? By removing the forever loop it will still look at WHEN STARTED, do all the set commands once, and after the last one then jsut keep responding to any of the WHEN commends being executed?
Correct, a forever loop never leaves the loop (you can call another function from within the loop, but it returns back to the loop once that function is complete), hence why if/then is required as it just cycles through a bunch of checks.
Since VEXCode already has Button Pressed events, those are designed to already listen to those buttons being pressed or joysticks being moved. So, all you really need to do is to set your velocities and brake modes after the When Started. And leave the When Button Pressed as they are.