My robot has spasms, Please help with ideas, or fixes

image
This line of code causes my robot to have wheel spams. It is in a forever loop. It works if I use drive stopping, so it would normally work. Is this an issue I can fix if I swap it to text? It only goes forwards, and if I try to go backwards it starts having spasms. Same with turning

Can we see all of the code please?

if you are trying to make a low-power mode with the press of a button, then use an if/else block. it should be something like the following: if controller L1 is pressed, set drive velocity to 20%, else, set drive to 75%, then put that in a forever loop. if this isn’t your intent then an explanation or more code would help.

1 Like

This is it. It has a drivetrain and controller set up. That is all.

Could you use a wait until Controller1 L1 Pressed block instead of a while loop?

The constant setting the velocity to 20% may be messing with the robot.

1 Like

Can you explain what you are trying to do? Foster would say this is the XY problem since none of us are sure what your goal is.

4 Likes

and if you are trying to control the drivetrain by assignment to the controller that will conflict with these blocks. You really have to choose either simple graphical setup and assign the drive to controller joystick or use blocks to program it.

6 Likes

All right, let’s see what we can figure out.

The first thing you should know is what happens when you configure the joysticks to drive the robot. Supposing you select tank control, it generates pre-written code in the background that looks something like this:

while (true) {
  set left drive velocity to left joystick position
  set right drive velocity to right joystick position
}

Then in your code, you put alongside that:

while (true) {
 set left and right drive velocity to 20%
}

Obviously, those two infinite loops conflict each other. One sets the velocity to your joystick position and the other to 20%.

It gets worse. You say,

As you may have figured out, this is because one loop sets the velocity to something like -100% and the other to 20%, so it’s constantly switching back and forth between forward slowly and backward quickly, which is what you describe as “spasms”.

While it would have been nice if you had explained better, I’m assuming your goal here is to have a button which, while you press it, slows down the robot so you have greater precision. The only way I can think of to do this is to stop using the default drive-train and controller configuration. Something like this:

variable driveMultiplier gets 1;
while (true) {
  if Controller L1 pressing {
    make driveMultiplier = 0.2;
  }
  else {
    make driveMultiplier = 1;
  }
  // Insert code appropriate to your preferred controlling method
  // I'll help you with that if you want, but you explain more, first
5 Likes

The “set velocity” is set a state of motor, if you want to change the motor from forward to reverse or stop, you need to make sure it has only one state all the time

2 Likes

I don’t think so? I’m not really sure what you mean, though… The set velocity does not

  • spin the motor forward,
  • spin the motor reverse, or
  • stop the motor.

If you set velocity to 50 rpm and then stop motor and then spin motor forward, it will spin the motor forward at 50 rpm. If you stop motor and then set velocity to 50 rpm, it will remain stopped, because set velocity does not spin the motor. If you then spin motor forward, it will spin at 50 rpm, since it was set to that last.

5 Likes

I have 3.5 hours of time later, I will test to see if this works. Thank you!

@242EProgrammer
|322px;x388px;
This made it so when I press L1/L2 I go forwards/backwards. It works great and adds extra torque instead of speed.

Uhh, I’m pretty sure code can’t add torque. Torque is physical strength, and motors, I think, don’t get physical strength just because they’re slower. Somebody?

I’m also curious if it worked; I believe it only set the drive velocity to 20% once, so the background joystick code would overwrite it with constantly setting the velocity to zero. Try driving forward with the controller, pressing and holding L1, letting off the joysticks, and after a minute, letting off L1.

3 Likes

That is true, It just seems like it because it has much better traction now.

Correct, torque is a measure of rotational force, speed is a measure of distance traveled, OP might be noticing that the wheels were slipping because of the speed, and now that it is slower it might be slipping less. I really don’t understand what you guys are trying to do but good luck on it! If you need any help with the block coding aspect of IQ feel free to message me!

1 Like

Torque is a measurement of rotational force not linear power.

And speed is not distance travelled, it is the rate at which the distance was traveled

1 Like

Close Enough, Will edit

I think what @77240G-SC is trying to do is make buttons that will make the robot go slower, for something that needs precision like collecting rings or something. I’m not sure what exactly, but I think that’s what he wants. Is that right, @77240G-SC?

P.S. I could help you much more if you explained better what you want. How about something like this:

when start:
set variable slowMultiplier to 0.2;

when driver_control:
  forever: 
    if Controller1 button L1 pressed:
      set drive velocity to Controller1 axis 1 percent;
      drive forward;

If there is a Controller Disable block, I think something like this would be even more effective:

when start:
set variable slowMultiplier to 0.2;

when driver_control:
  if Controller1 button L1 pressed:
    Controller1 disable;
    set drive velocity to Controller1 axis 1 percent * slowMultiplier;
    set turn velocity to Controller1 axis 2 percent * slowMultiplier;
    drive forward;
    turn left;
  else:
    Controller1 enable;

Only problem is I’m not sure what would happen if you said turn left at -20% velocity and I’m not certain exactly what Controller Disable does. In IQ (which I am in), it just turns off configured driving by the controller. If in V5 it actually disabled communication with the controller,… Let’s just say you would have problems.

5 Likes

This is what I was wanting to do, but we found a solution. Thanks to everyone for their contributions!

1 Like

So what was your solution?