I need to get my robot to turn during auton and don’t want to have to switch motor values during auton, we want to be able to spin each motor group the opposite ways at the same time during auton thanks for the Help!
Yes, this is definitely possible. Blocks or text? If using blocks, you can use the white arrow at the end of the block to extend the “and don’t wait” part:
You can do the same in C++:
MotorGroup1.spinFor(forward, 90.0, degrees, false);
MotorGroup3.spinFor(forward, 90.0, degrees, true);
and Python:
motor_group_1.spin_for(FORWARD, 90, DEGREES, wait=False)
motor_group_3.spin_for(FORWARD, 90, DEGREES, wait=True)
These examples would spin both motor groups 90 degrees simultaneously.
I’ve tried doing this Before it will do one line then the next, I’ll try it but I probably won’t work.
The order is vital. The first line with the extra “false” parameter has to go first, then the second line without it (or add an explicit “true” to make the parameter counts match and the code more readable by someone else, but hey, that’s just good coding practice talking).
Also, not sure why you started a second topic for this, but the original code you had with &&
between two calls is not doing anything. That is a logical AND
operator for C/C++, and you’re not testing logic with those statements, so it’s not doing anything good, and very possibly could be causing you problems.
Yes the order is vital, I don’t have a lot of coding knowledge, but enough where I’ve tried a lot to fix this issue again, I haven’t tested this specific suggestion, but I have tried others similar to it and that is why I’m skeptical, and regarding making a different post why wouldn’t I? That was for driving forward and backwards, this should be simple but not as simple as creating motor groups. Also why are you taking such a cynical approach when you haven’t even suggested anything to help? All you’ve done is talked down to me for being skeptical.
No one is trying to be cynical and talking down to you for being skeptical, and they have tried to help. They are just trying to inform you how to use the forum properly to prevent clutter and make it easier to use for everyone.
I think you’ve misinterpreted what I’m trying to say, so let me clarify.
In this post you posted this code:
RightDrive.setVelocity(100, percent);
LeftDrive.setVelocity(100, percent);
RightDrive.rotateFor(reverse, 42, rotationUnits::rev) && LeftDrive.rotateFor(reverse, 42, rotationUnits::rev);
I’m calling out this line specifically (I’ve added ^^
to clarify) what I’m going to talk about:
RightDrive.rotateFor(reverse, 42, rotationUnits::rev) && LeftDrive.rotateFor(reverse, 42, rotationUnits::rev);
---^^---
That &&
in the middle of that line is what’s not doing anything for you. This should be written as:
RightDrive.spinFor(reverse, 42, rotationUnits::rev, false);
LeftDrive.spinFor(reverse, 42, rotationUnits::rev, true);
(Note that I’ve added in the needed “false” for `waitForCompletion per this API description on the first spinFor command.)
What I was trying to point out is that &&
only works if you’re trying to do a logical comparison to make sure that two conditions are both true to proceed. You would use it something like:
if((sky == blue) && (water == wet))
paint(clouds);
Having &&
between two function calls does not make them run in parallel, but it could cause one to run before the other and not give you expected results. Unless you know very specifically the order that a compiler builds things, what you’ve done with that bit of code is going to be unpredictable. Keep in mind that for a brain like the V5, it can only do a single operation at a time. Technically even the “wait for completion” being set to false still starts one motor after the other, just a very small amount of time behind enough that it won’t really matter much.
TL;DR: Take out the &&
between your function calls, make them independently executable statements, add in the “false” and then “true”, and it will work. This is how it’s designed to happen.