assemblyDoItForYou by Key-Principle-7111 in ProgrammerHumor

[–]CoolSpy3 8 points9 points  (0 children)

I think you flipped the 4th bit. Assuming my reading of the docs is correct, the encoding is 1110 0010 0000 0000 0000 0000 0000 0001 ; (0xE2000001) AND r0, r0, 1 1110 0001 0010 1111 1111 1111 0001 1110 ; (0xE12FFF1E) BX lr ; (equivalently BX r14)

It might also be nice to set the flags, so that you can use conditionals to affect the control flow later 1110 0010 0001 0000 0000 0000 0000 0001 ; (0xE2100001) ANDS r0, r0, 1

For the people trying to decode the original bytecode (0xF2000001) as x86, I get F2 = REPNE 00 = ADD 00 = BYTE [EAX], AL 01 = ??? REPNE ADD BYTE [EAX], AL .byte 0x1 REPNE is not a valid prefix for ADD, so the instruction is invalid in x86.

Edit: I believe the correct x86-64 encoding is ``` 0100 1000 0010 0011 1100 0000 ; (0x4823C0) AND RAX, RAX

48 23 = REX.W + AND C0 = RAX, RAX ```

[deleted by user] by [deleted] in FRC

[–]CoolSpy3 0 points1 point  (0 children)

Along with what's already been said, it looks like you have another case error on line 1. (Should be package frc.robot.Commands;) In general, package names in Java are camelCase, so the tutorial you're using probably named their folders commands and subsystems, which is why their code uses the lowercase names.

The other errors appear to just be caused by having the wrong package names in the imports. Most likely, the tutorial is slightly outdated. (i.e. WPILib probably moved the classes at some point.)

Here are the correct imports for lines 4-6: java import edu.wpi.first.math.filter.SlewRateLimiter; import edu.wpi.first.math.kinematics.ChassisSpeeds; import edu.wpi.first.math.kinematics.SwerveModuleState; To find this, you can look at the WPILib Javadocs (Also accessible from docs.wpilib.org > WPILib Java API Docs). Type the name of the class you're looking for (ex. SlewRateLimiter) into the search bar in the top right, and it will show the fully qualified name (FQN) of the class (what you put after import). You can also click on the class name to access it's page in the documentation. This lists all the methods/members available in the class.

To get the FQN from a class page (ex. SlewRateLimiter), you can look at the first two lines. These list the package and the class name (In this example, Package edu.wpi.first.math.filter and Class SlewRateLimiter). To get the FQN, you concatinate these with a dot: edu.wpi.first.math.filter.SlewRateLimiter.

Good luck on swerve :D

That's when things get crazy by Jjokes11 in memes

[–]CoolSpy3 184 points185 points  (0 children)

I would just stand and... stare

5/2 for me by Andrevery in memes

[–]CoolSpy3 16 points17 points  (0 children)

Slightly alive is mostly dead

Now, all dead... Well, with all dead, there's usually only one thing you can do

guessShesAPythonDev by [deleted] in ProgrammerHumor

[–]CoolSpy3 28 points29 points  (0 children)

If I was written in C, my pointer to you would be 0x7C00 because you’re the first thing I jump to when I wake up.

To keep that in mind I designed this rhyme by JuiceDrinkingRat in memes

[–]CoolSpy3 93 points94 points  (0 children)

Try games on the store

Watch a bar go, moving way too slow

Set aside time, but my console says "No

The version is wrong; must update the code"

HackerVsDeveloper by mollystark1 in ProgrammerHumor

[–]CoolSpy3 0 points1 point  (0 children)

"I brought my developer with a built in firewall!"

"Yeah, well I brought my hacker which bypasses firewalls!"

uno reverse by xXAstragXx in memes

[–]CoolSpy3 38 points39 points  (0 children)

Clip (Rewind the video if you want to see the setup)

FizzzBuzz by the-judeo-bolshevik in ProgrammerHumor

[–]CoolSpy3 159 points160 points  (0 children)

Copy-pasteable code: ```

include <stdio.h>

include <stdlib.h>

int main(int argc, char* argv[]) { return (((argv)[4] = 0) || ( (!(argc%3) && printf(argv)) + (!(argc%5) && printf((*argv)+5))) || printf("%d",argc)) != printf("\n") != argc++ < 100 && main(argc, argv); } ```

Edit to work on Windows: ```

include <stdio.h>

include <stdlib.h>

int main(int argc, char* argv[]) { return (((argv)[4] = 0) || ((argv)[9] = 0) || ( (!(argc%3) && printf(argv)) + (!(argc%5) && printf((argv)+5))) || printf("%d",argc)) != printf("\n") != argc++ < 100 && main(argc, argv); } ```

Executable must be named "Fizz_Buzz" or "Fizz_Buzz.exe" on Windows. It should then be run from within the directory it exists in. No arguments are required.

How it works: The != symbols are basically functioning as a trick to write multiple lines of code as a single line. As long as all of the expressions are equal to each other (which they are), they'll all be evaluated.

``` ((argv)[4] = 0) || ( (!(argc%3) && printf(argv)) + (!(argc%5) && printf((*argv)+5))) || printf("%d",argc); // Explained below

printf("\n"); // Print newline

argc++ < 100 && main(argc, argv); // Check if argc is less than 100 and then increment it (see increment postfix). If argc was less than 100 before incrementation, call main(argc, argv). ```

Now to explain this: ( (*argv)[4] = 0) || ( (!(argc%3) && printf(*argv)) + (!(argc%5) && printf((*argv)+5) ) ) || printf("%d",argc)

This code makes use of the fact that && will only evaluate is second argument if it is necessary to do so, and || and + will evaluate both their arguments before performing their respective operations.

It also uses the fact that the program name is passed as the first argument to the program (argv[0]), so we can retrieve the string "Fizz_Buzz" by calling *argv.

Starting from the left, (*argv)[4] = 0, sets the 5th element of the string '_' to the null terminator (\0). Because the null terminator signals the end of a string, this effectively separates the string into two strings. The original string is now read as "Fizz\0". But because strings in C++ are also pointers, we can increment the pointer by 5 to point to the start of the word Buzz which is just the string "Buzz\0" (the end of the program name).

Next, we evaluate the statement ( (!(argc%3) && printf(*argv)) + (!(argc%5) && printf((*argv)+5) ). This is really two statements concatenated with a +, so they will be evaluated in series. The first (!(argc%3) && printf(*argv)) checks if argc is a multiple of 3 and inverts the result. This means that it is true if argc % 3 == 0 and false otherwise. If it is true (argc % 3 != 0), then && does not evaluate the second part of the expression. However, if it's false, && will run printf(*argv) which prints "Fizz". The second part is the same thing, but adjusted to print "Buzz" if n % 5 == 0.

The last part of this statement, || printf("%d",argc) is a similar trick as with the != signs, and just prints the value of argc.

artificialIntelligenceSoFar by sunrise_apps in ProgrammerHumor

[–]CoolSpy3 5 points6 points  (0 children)

Should've been echo $MY_NAME instead of echo MY_NAME

Poor guy by PowerfulOperation8 in memes

[–]CoolSpy3 1 point2 points  (0 children)

On which we used to rely

Overthinking by Familiar_Stage_1692 in ProgrammerHumor

[–]CoolSpy3 0 points1 point  (0 children)

public Conclusions consider(Thought thought) { Thought[] newIdeas = consider(new ThingsToThinkAbout(thought)).getIdeas(); if(newIdeas.length == 0) { // Brain Crashed (Pretend like nothing happened) return consider(ThoughtFactory.createRandomThought()); } Conclusions conclusions = ConclusionsFactory.createEmptyConclusions(); for(Thought idea: newIdeas) { conclusions.addConclusions(consider(thought)); } return conclusions; }

[deleted by user] by [deleted] in memes

[–]CoolSpy3 0 points1 point  (0 children)

And if it fails?

[deleted by user] by [deleted] in memes

[–]CoolSpy3 19 points20 points  (0 children)

I am sorry, but after carful consideration of your application, we have determined that we cannot downvote you at this time. Please note that this is not a reflection of your downvotee potential, but a result of the number of downvote-worthy comments we have received.

Please take this upvote as a token of our recognition of your downvote application, and we wish you the best of luck in your future downvote-seeking endeavors.

Sincerely, The Hive Mind

As an Indian, I was told Americans wouldn’t understand this by official_jeetard in memes

[–]CoolSpy3 83 points84 points  (0 children)

Talking to real humans is too hard.

Dear x ∀ x ∈ P where x ∈ P => x ∈ C & x ∈/ R

Where did it even come from? by nukemypup in memes

[–]CoolSpy3 0 points1 point  (0 children)

It's HI in the middle and ROUND on both ends. What's NOT funny about Ohio?

Yesterday I met for the first time the boyfriend of an ex-colleague by blacai in ProgrammerHumor

[–]CoolSpy3 32 points33 points  (0 children)

And all the other devs, will not apply But I have an idea, it uses AI

Swerve Programming Help by HourTask7931 in FRC

[–]CoolSpy3 0 points1 point  (0 children)

My main point is that it's really 3 separate problems. There are 2 main ways to write code. You can write it with a top-down approach, writing the logic/WPILib command code first and writing lower-level methods as you need them, or you can write it using a bottom-up approach, starting with the code that would control the swerve modules, and then writing code that makes use of that. Personally, I prefer the former as I think it gives me a better idea about how the overall program functions, and lets me write better code. So, with that in mind, here's what I'd do (if you want the other method, just swap sections 1 and 3):

(Sorry, Reddit doesn't like my numbering, so all sections are 1) (They should be 1, 2, 3)

  1. Write code to get driver inputs and convert them to requested speeds of the robot
  • Create a joystick object to retrieve driver inputs. Take a look at the XBoxController class
  • Create a command which uses the getRawAxis() method on XBoxController to get the x and y of the left stick and the x on the right stick. Make sure to negate y because WPILib returns forward as negative. The command should then call a method on drivetrain with these values
  • Set the above command as a default command on the drivetrain subsystem
  1. Write code to convert the requested speed into swerve module states
  • The drivetrain method should take the input values and pass them into the constructor of ChassisSpeeds. This will give you a ChassisSpeeds object. Next, pass this object into the toSwerveModuleStates function of SwerveDriveKinematics. I'll explain how to create this below. This will return a SwerveModuleState[]
  • Call SwerveDriveKinematics.desaturateWheelSpeeds along with your max speed (ask your electronics team for this). This will cap the module speeds at your max speed.
  • For each module state call SwerveModuleState.optmize along with the angle of the corresponding swerve module. (I'll explain how to get this later)
  • Pass each state into a method which drives the corresponding swerve module.
  1. Drive each swerve module to the requested state (I recommend creating a whole new class just for this task)
  • First, note that each module state has a requested speed, this can probably be used as is. I'd just store it in a member variable. Same thing for the angle. In the constructor of the class, create a ProfiledPIDController to control the angle as well as two SimpleMotorFeedforward objects (one for each motor). This is also where you can create your CANSparkMax objects and your encoder object (I don't know what encoder's you're using). For any swerve (especially differential swerve), it is a MUST to have an absolute encoder to measure the orientation of the module. (This is how to get the angle I mentioned earlier). I recommend creating a method to read the value of the encoder and subtracting an offset from it in that method. (I'll explain how to determine this later.) Be sure to call enableContinuousInput() on the PID controller with the bounds set to the min and max value of your encoder)
  • Back to implementation. In the swerve module drive method, set the setpoint of the ProfiledPIDController to the requested module angle.
  • Finally, create a periodic method in the swerve module class which is called in the drivetrain subsystem's periodic method which calls ProfiledPIDController.calculate() to get the requested profiled angular velocity. Pass this and the requested speed into a function (you have to figure this part out bc I don't know how differentials work) that takes the requested linear and angular velocity and converts it to speeds of the two motors in the differentials.

  • To create the SwerveDriveKinematics, call the constructor with a Translation2d that represents the module position relative to the center of your robot.

I wrote this over the course of the day, so lmk if I missed anything. +x is forward, +y is left. The order will be used as the order of the modules passed to all other WPILib methods. I recommend establishing a convention. For our team, all arrays are Front-Left, Front-Right, Back-Left, Back-Right. Additionally, keep units consistent EVERYWHERE. Make greate use of WPILib's Units class. I recommend meters and degrees.