Announcement

Collapse
No announcement yet.

Servo Problems

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

  • Servo Problems

    We're trying to make our servos rotate via the joystick. When we press a button, we want the servos to go either up or down. Here's the code:

    #pragma config(Hubs, S1, HTMotor, HTServo, none, none)
    #pragma config(Motor, mtr_S1_C1_1, motorA, tmotorNormal, PIDControl, encoder)
    #pragma config(Motor, mtr_S1_C1_2, motorE, tmotorNormal, openLoop)
    #pragma config(Servo, srvo_S1_C2_1, servArm1, tServoStandard)
    #pragma config(Servo, srvo_S1_C2_2, servArm2, tServoStandard)
    //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

    #include "JoystickDriver.c"
    void initializeRobot()
    {

    return;
    }

    task main()
    {
    initializeRobot();

    waitForStart();



    int i = 0;

    while(i < 3)

    motor[motorA] = 100;
    wait1Msec(2);


    if(joy1Btn(1))

    servo[servArm1] =250;

    if(joy1Btn(3))

    servo[servArm2] =0;

    }



    However, when the button is pressed, nothing happens. Help?

    Thanks.

  • #2
    i believe that you have an infinite loop in your program from the segment
    int i = 0;

    while(i < 3)

    motor[motorA] = 100;
    wait1Msec(2);
    which would explain why your servos are not responding because it never reaches that point in the code

    Comment


    • #3
      Watch those curly braces

      I can get you part way there. We are having servo issues ourselves. RobotC doesn't like servo[servoArm] = 0;, for example. I think ours is a driver or setup issue.

      What I did notice about your code is the following:

      Your loop has no curly braces around the code. Other than your initializing code, like including joystick drivers, function definitions, etc., all of the working code should be in your while loop.

      Also, don't forget to get your joystick settings while in the loop.

      task main()
      {
      while (true) // We use while (true) as another form of an infinite loop {
      getJoystickSettings(joystick); // Don't forget to get the joystick settings
      // add all of the code you want for joystick control in here
      }
      }

      Comment


      • #4
        You have to use the servoTarget[] array. To the best of my knowledge, servo[] doesn't exist.
        Max Bareiss

        FTC #248 Fatal Error (2009-2013)
        FRC #3142 Aperture (2009-2012)
        FRC #1302 Team Lionheart (2012-2013)
        ZRHS #89 Team K├╝hlschrank (2011-2013)
        ZRAC #40 Catcher in the Skye (2012)
        ISR 12: Umptysquatch 6
        Rowan University Baja SAE

        And mentoring for life.
        --
        11 seasons of FIRST in 6 years, as a student. Many more as a mentor.

        Comment


        • #5
          Did you check your code for errors? Sorry, we used RobotC last year but this year we switched to LabView so I can't tell if it's correct or not. But you do need to get out of the infinite loop like that, so add i++ somewhere in there. Sorry if this doesn't work, though.

          -T-REX team 2944
          -T-REX team 2944
          http://www.sonoranacademy.org/t-rex2944

          Comment


          • #6
            I believe what you want is

            Code:
            #pragma config(Hubs, S1, HTMotor, HTServo, none, none)
            #pragma config(Motor, mtr_S1_C1_1, motorA, tmotorNormal, PIDControl, encoder)
            #pragma config(Motor, mtr_S1_C1_2, motorE, tmotorNormal, openLoop)
            #pragma config(Servo, srvo_S1_C2_1, servArm1, tServoStandard)
            #pragma config(Servo, srvo_S1_C2_2, servArm2, tServoStandard)
            //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
            
            #include "JoystickDriver.c"
            void initializeRobot(){
              return;
            }
            
            task main(){
              initializeRobot();
            
              waitForStart();
            
              while (1){
                getJoystickSettings(joystick);
            
                motor[motorA] = 100;
                wait1Msec(2);
            
                if (joy1Btn(1))
                  servoTarget[servArm1] = 250;
                if(joy1Btn(3))
                  servoTarget[servArm2] = 0;
              }
            }
            Qingyang Chen
            FTC Team 5485 - PRO, Horseheads, NY
            Sponsored by Corning Inc.
            Join our fan page: http://www.facebook.com/ftcpro

            Comment

            Working...
            X