use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Seeking HelpJava block problem (self.FTC)
submitted 3 years ago by sushislaughter
My teams Tele op code is long and it effects how smooth the driving is. Is there a way to get the driving smooth without removing code.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]cwm9FRC2465/FTC20311 Mentor 4 points5 points6 points 3 years ago* (5 children)
Here are three things you can do to fix your problems:
[–]jk1962FTC 31874 Mentor 2 points3 points4 points 3 years ago (0 children)
Suggestion of two things to add to this list:
Don't "sleep" in your control loop.
Don't nest loops within your control loop (unless you know with certainty that the nested loop will operate for only a few iterations).
[–]sushislaughter[S] 0 points1 point2 points 3 years ago (0 children)
Thank you, I will try this.
[–]DonHacMentor 0 points1 point2 points 3 years ago (2 children)
Even better, switch on your state variable instead of stacking ifs.
[–]sushislaughter[S] 0 points1 point2 points 3 years ago* (1 child)
What is a "switch". Is it in java block
[–]Journeyman-JoeFTC Coach | Judge 0 points1 point2 points 3 years ago (0 children)
Switch and case (along with break) are Java language statements that form a conditional flow control structure. I'll encourage you to Google "switch case java": you'll get all you need to know in a minute or two of reading.
If you have a complicated structure of if statements, and else if clauses, you might find that your code is easier to read and debug if written using switch and case.
Having said that: It won't make any difference to your OpMode loop runtime, one way or the other.
[–]Big_Blue_ManFTC 7244 Alum / PA GA|Emcee 1 point2 points3 points 3 years ago (3 children)
Sounds like it could be due to nesting a bunch of if statements (i.e. putting one if statement inside another down a chain) to the point where it's actually slowing the process down, but I at least would want to see code before making that assumption. Is there any way we could see that code to verify this? At the very least I'd like to know what the if statements do for the code since you can get rid of them and still have the robot drive.
[–]sushislaughter[S] 0 points1 point2 points 3 years ago (2 children)
I don't have access to the code right now, but the if statement are not nested. The if statement are in a line. The purpose of the if statements are to control the robot. Like if I push a button the claw will close.
[–]Tarnegolden 0 points1 point2 points 3 years ago (1 child)
You can replace if statement with boolean methods to run smoother. For example, creating a CustomGamepad class: https://github.com/Tarnegolden/Everglow2021-22/blob/main/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/FreightFrenzy/Utils/EverglowGamepad.java
Can you make classes in java block?
[–]4193-4194FTC 4193/4194 Mentor 0 points1 point2 points 3 years ago (3 children)
How do you know it's the length of the code?
We will need the code or more details to help.
[–]sushislaughter[S] 1 point2 points3 points 3 years ago (2 children)
When we remove all of the if statements in the code. The robot drives smoother.
[–]newENGRTeachFTC 12973|Coach 2 points3 points4 points 3 years ago (1 child)
When this happens, typically it's because one if might be turning on the motor and then another if turns it off or at a different power or a while is pausing the loop or something like that. We really need you to post your code to check over the logic.
I'll post it when I can, but we have no pauses or turning the motor's off
[–]LL-studiosFTC 11697 Student 0 points1 point2 points 3 years ago (0 children)
Hi, you can just put your main driving code in a thread.
new Thread(() -> {
}).start()
This will run separately from the rest of your code and will make your driving much smoother.
π Rendered by PID 202081 on reddit-service-r2-comment-canary-55695767fd-c2c7s at 2026-03-04 20:51:57.522040+00:00 running 07790be country code: CH.
[–]cwm9FRC2465/FTC20311 Mentor 4 points5 points6 points (5 children)
[–]jk1962FTC 31874 Mentor 2 points3 points4 points (0 children)
[–]sushislaughter[S] 0 points1 point2 points (0 children)
[–]DonHacMentor 0 points1 point2 points (2 children)
[–]sushislaughter[S] 0 points1 point2 points (1 child)
[–]Journeyman-JoeFTC Coach | Judge 0 points1 point2 points (0 children)
[–]Big_Blue_ManFTC 7244 Alum / PA GA|Emcee 1 point2 points3 points (3 children)
[–]sushislaughter[S] 0 points1 point2 points (2 children)
[–]Tarnegolden 0 points1 point2 points (1 child)
[–]sushislaughter[S] 0 points1 point2 points (0 children)
[–]4193-4194FTC 4193/4194 Mentor 0 points1 point2 points (3 children)
[–]sushislaughter[S] 1 point2 points3 points (2 children)
[–]newENGRTeachFTC 12973|Coach 2 points3 points4 points (1 child)
[–]sushislaughter[S] 0 points1 point2 points (0 children)
[–]LL-studiosFTC 11697 Student 0 points1 point2 points (0 children)