V5 Motor disconnect warning on controller

I have an issue with my flywheel motor, number 6 randomly disconnecting from the brain and the flywheel not working correctly.

I would like to have some sort of rumble and alert on the controller to let me know if a motor has disconnected, and which one has disconnected, just by showing a number or something. On the controller. I just figured out rumble, and I know how to type something on the controller, the hard part is getting the brain to tell you that the motor is disconnected.

Keep in mind that I am using block code, and I don’t really care how long the code is to get it to work.

1 Like

A way to not need to make this, (as I’m pretty sure it is not possible), is to just switch the port or wire of the motor so that a disconnect doesn’t happen.

Hope this helps, will be happy to help with anything else!
- Henry 344E

I know you can definitely do that, In fact port 1 on the brain was dead, so my drivetrain is actually motors 2,3,4, and 9. This is because I ran out of holes on the top of the brain, and the bottom of the brain is very out of the way and low to the ground, so It’s not exactly an option for plugging things into. I kinda just want a way to tell when it disconnects so I know not to use they flywheels during a match so i don’t damage them.

It is not possible to detect disconnects. You also mentioned ports 2, 3, 4, and 9. Is port 5 open?

You can detect device disconnects using text, but not blocks.

4 Likes

No,
Ports 2,3,4,9 are drivetrain
Port 8 is the intake
Port 6 and 7 are the flywheels
Port 5 is the indexer
Port 1 and 10 are both dead
The one on the side is the radio (21?)

How? I think most things in text do carry over to blocks. The only thing I’ve found is missing is a toggle, but that’s a work in progress.

The installed() motor class member function will tell you if a motor is installed on a particular port. example of use.

    while(1) {
      for(int port=PORT1;port<PORT22;port++) {
        vex::motor m(port);
        if( m.installed() ) {
          // do something with a detected motor
        }
        else {
          // no motor on this port
        }
      }
      this_thread::sleep_for(100);
    }
6 Likes

Us block coders have made custom toggles, just using if else blocks and booleans, is there some sort of built in toggle in text coding?

How do you make a toggle? LIke, press the button once to start a motor spinning, and press the same button again to stop. I haven’t figured out how to do that.

Toggles can be done with Events (aka ‘When’ in Blocks). They fire once each time you press and release a button.
image

bool Running = true;

int Init() {
  return 0;
}

void Motor1Controller() {
  if (Running) {
    Motor1.setVelocity(50.0, percent);
    Motor1.spin(forward);
  }
  else {
    Motor1.stop();
  }
  Running = !Running;
}

int main() {
  // Register the Motor1Controller event.
  Controller1.ButtonX.pressed(Motor1Controller);
  wait(15, msec);
  Init();
}
2 Likes

Can I put an If statement around the whole thing saying that x was pressed, due to competition code and the fact that it has to be in one long list of code?

(Inside my code)
Screen Shot 2023-03-28 at 2.26.12 PM

It does not need to be in a single long list of code, that would be difficult to navigate at least for me. You can multithread (use multiple “when driver control” hat blocks), and the code shown by Hudsonville_Robotics would work fine in a competition bot, as long as you don’t press the trigger during autonomous. I am not sure if the field control automatically disables the controller during auton period, but if you would like to avoid an accidental autonomous-control activation, you could code the bot to disable the controller until driver control starts. However, the code you showed would work fine, just wouldn’t be the main choice for lots of people I’ve met.

It doesn’t have to be in one long list of code. The advantage of events is that they separate the responsibilities of the code. The competition template knows how to handle events too.

If you don’t want to use events, then you need to add a latching variable. Events fire one time for each button press. If you are using an in-line if statement, the code fires once for every loop. This means that your code would repeat on - off - on - off when you held the button down. The latch adds an extra layer that locks the state after it has changed one time.

This is an example of an in-line toggle.

1 Like

That’s interesting. I’m really not a coder, we had a coder last year but he went to another team, and I was willing to try it. I was told by the rest of my team that hat blocks wouldn’t work in driver control at all. I’ll seperate the code and try it in the future

1 Like