Announcement

Collapse
No announcement yet.

stop() method not working?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • stop() method not working?

    Context: 2 Rev hubs running 1.6 firmware. Current Android Studio SDK. ***Interative Opmode, not linear.*** Servos commanded by slave rev hub through Rev servo power module. (important since while the rev Hubs will power down their servo ports when the code stops, the SPM do not and leave power to the servos. Digital servos, by default, remember their last command upon loss of signal pulses, unlike the analog ones. The servos themselves are not Rev smart servo, in case that somehow matters.

    Anyway...

    The kids have some lines of code in their stop() method to make sure motors and especially digital-continuous-rotation-servo motors are given a command to a good, non-spinning, state when somebody pushes stop.

    Problem is it looks for all the world like when the stop button is pushed on the DS phone, their stop() method doesn't run. (or always run, or always get to complete?). They have a fun case where some digital continuous rotation servos can keep on spinning after the stop button is pushed. And looking on an oscilloscope at the pulses going to the servo from the rev SPM, the pulses never contain the 1.5mS "center" width pulses as things shut down. The rev hub just seems to stop sending pulses (in this case 0.6 mS ones that are commanding the intake motor to spin really fast). And since the digital servo has power, it just remembers the last command and keeps on going.

    They even put a 1 second second delay at the end of stop() so there was no missing the method running. It really looks like pushing the stop button on the DS just shuts the party down outside whatever code the kids have in stop()


    I'm probably missing something obvious here. So I'd appreciate a pointer from one of ya'll more software capable folks.

    thanks!

    Coach Z


  • #2
    Correction: They are on 1.7.2 firmware not 1.6.

    Comment


    • #3
      The SDK attempts to send the appropriate "safe" condition to the servos, based on whether you have defined them as a Regular or Continuous Rotation servo.

      eg: If you have defined the servo as Continuous Rotation in BOTH the Robot Configuration, AND the Opmode, then when the opmode ends, and reverts back to the Stop$Robot opmode, the SDK will send a 0.5 output command before disabling the Servo Controller. This should have the effect of stopping a CR servo.

      Having said all this, I know that I have verified this on on the Legacy and MR servo controllers, but I'm not 100% sure I've actually verified this on the REV controller, but I would expect it to be the case (since the same code is running in Stop$Robot in both cases).

      So, the question is: Have you defined the servo in question as a continuous rotation one in the Robot configuration?

      Phil.


      Comment


      • #4
        Sorry for the delay Phil. Just got back with the kids today.

        The code and the Robot config on RC phone are both configured as CR servo

        They have these lines creating the instances in code look like this:

        The lines

        final public double LEFT_INTAKE_GO = 1.0; // position for intaking/ejecting
        final public DcMotorSimple.Direction LEFT_INTAKE_IN_DIR = DcMotorSimple.Direction.REVERSE; // should we be using Servo.Direction?
        public double leftIntakePower; public DcMotorSimple.Direction leftIntakeDirection;
        public CRServo leftIntake; // in init()
        leftIntake = hardwareMap.crservo.get("leftIntake"); // in loop()
        leftIntakePower = LEFT_INTAKE_GO; leftIntakeDirection = LEFT_INTAKE_IN_DIR;
        leftIntake.setPower(leftIntakePower); leftIntake.setDirection(leftIntakeDirection); And in their stop() method they set those intake powers to zero and then do leftIntake.setpower and so on for all the CR servos. So if the stop() method is being allowed to run they should be stopping the servos. Right? When I looked for them with my o-scope it really seemed like there were a series of 0.6 mS pulses (ie full speed for that CR servo) and those pulses just ended when stop was pushed. Even with a 1.5 second do nothing while loop at the end of their stop() method. So it seems to me like the stop method the kids are provided to use never happens. Or not always. And the rest of the shutdown stuff that is built into pressing the stop button on the DS just overrides it all. And in the case of Rev, without making sure there was a 1.5 mS pulse train for a while as shutdown happened?

        Comment


        • #5
          sorry for the terrible formatting there. Not sure what happened.
          Still no evidence the stop() runs when they push the stop button on the DS. They tried a few more things and are just working without it for now.

          Comment


          • #6
            Maybe I'm misunderstanding things, but isn't this all inside of a
            Code:
            public class BasicOpMode_Iterative extends OpMode
            {
                ...
                public void loop() {
               ...
                }
            
                /*
                 * Code to run ONCE after the driver hits STOP
                 */
                @Override
                public void stop() {
                }
            }
            A dumb thing to check (and a reason some people don't do curly braces that way[1]) is to make sure the "public void stop()" is declared outside of the curly brace that closes out the "loop" method.
            It sometimes happens that an extra brace will get added or that the indentation gets a little messed up.

            [1] I'm not fussy about it, but given my druthers, I often find this a little easier to understand:
            Code:
            public class BasicOpMode_Iterative extends OpMode
            {
                ...
                public void loop()
                {
                     // lots of good code in here
                     ...
                }
            
            
                /* ****************************************************
                 * Code to run ONCE after the driver hits STOP
                 * ***************************************************/
                @Override
                public void stop()
                {
                    // "it's wabbit season"
                }
            }
            Mentor, teams 8578 & 11959

            Comment


            • #7
              Nope that's not it. They've pretty much worked around it, by using mostly all analog servos. But I wonder what's up or what they missed or if they are some of the only folks on iterative optmode and thus see an SDK bug few others do. ???

              Comment

              Working...
              X