Announcement

Collapse
No announcement yet.

Programming states

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

  • Programming states

    Does anyone know how to programme 'states'? This is when you press either the small E or F buttons on the controller and the brain will turn a motor a specific amount. Very useful if you want to raise or lower an arm to an exact position. Thanks

  • #2
    In what programming language?

    Comment


    • #3
      We do this using RobotC. We set a task up at the top with a global variable, similar to this:
      #pragma config(Motor, motor1, armMotor, tmotorVexIQ, PIDControl, encoder)
      //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

      int armState = 0;

      task armMovement()
      {
      if(armState == 0)
      {
      setMotorSpeed(armMotor, 0);
      wait1Msec(10);
      }
      if(armState == 1)
      {
      setMotorSpeed(armMotor, 25);
      wait1Msec(10);
      }
      }


      task main()
      {
      startTask(armMovement);

      while(true)
      if(getJoystickValue(BtnLUp) == 1)
      {
      armState = 0;
      while(getJoystickValue(BtnLUp) == 1)
      {
      wait1Msec(10);
      }
      }
      if(getJoystickValue(BtnLDown) == 1)
      {
      armState = 1;
      while(getJoystickValue(BtnLDown) == 1)
      {
      wait1Msec(10);
      }
      }



      }
      Last edited by daddycrusader; 10-09-2018, 03:17 PM.

      Comment


      • #4
        Originally posted by calvc01 View Post
        In what programming language?
        We use robotC graphical. Thanks

        Comment


        • #5
          If you are using the graphical version it would be difficult to do what you're asking. However, this can be done fairly easily with regular RobotC, as shown by DaddyCrusader. He takes advantage of multitasking. See his code. The task armmovement() does what you want. It is called from task main() as shown.

          If you like, you can write the non-task code in Graphical then convert the file to text. Under View|Convert Graphical File to Text. Once done a new file appears with a different extension (".c*"). It can also be compiled and downloaded to the robot after you have added in the desire task code. You can't go backwards to the Graphical version from here, but the original Graphical file is unchanged.

          Comment


          • #6
            Originally posted by Michael View Post
            Does anyone know how to programme 'states'? This is when you press either the small E or F buttons on the controller and the brain will turn a motor a specific amount. Very useful if you want to raise or lower an arm to an exact position. Thanks
            I can tell you that you need to check the rotation degrees and stop when it is equal to OR greater than your target. It's very hard to catch it when it is exactly equal to the target degrees.

            We did this using modkit. Use rotation degrees and a variable that toggles active/stop states (to reset for when you want to begin movement again).

            Comment

            Working...
            X