Announcement

Collapse
No announcement yet.

Motors Movement During TeleOp

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

  • Motors Movement During TeleOp

    We are a rookie team, and we've created this program to use during the TeleOp period.
    However, whenever we run it, the DC motors connected to the wheels never move.
    The only motor that seems to move is motor A which we aren't using for movement.
    This is our program, we would appreciate it, if someone knows what the problem is

    -- RoboAvatars


    #pragma config(Hubs, S1, HTMotor, HTServo, none, none)
    #pragma config(Sensor, S1, , sensorI2CMuxController)
    #pragma config(Motor, mtr_S1_C1_1, motorD, tmotorTetrix, openLoop)
    #pragma config(Motor, mtr_S1_C1_2, motorE, tmotorTetrix, openLoop, reversed)
    #pragma config(Servo, srvo_S1_C2_1, servo1, tServoStandard)
    #pragma config(Servo, srvo_S1_C2_2, servo2, tServoStandard)
    #pragma config(Servo, srvo_S1_C2_3, servo3, tServoNone)
    #pragma config(Servo, srvo_S1_C2_4, servo4, tServoNone)
    #pragma config(Servo, srvo_S1_C2_5, servo5, tServoNone)
    #pragma config(Servo, srvo_S1_C2_6, servo6, tServoNone)
    //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

    /////////////////////////////////////////////////////////////////////////////////////////////////////
    //
    // Tele-Operation Mode Code Template
    //
    // This file contains a template for simplified creation of an tele-op program for an FTC
    // competition.
    //
    // You need to customize two functions with code unique to your specific robot.
    //
    /////////////////////////////////////////////////////////////////////////////////////////////////////

    #include "JoystickDriver.c" //Include file to "handle" the Bluetooth messages.


    /////////////////////////////////////////////////////////////////////////////////////////////////////
    //
    // initializeRobot
    //
    // Prior to the start of tele-op mode, you may want to perform some initialization on your robot
    // and the variables within your program.
    //
    // In most cases, you may not have to add any code to this function and it will remain "empty".
    //
    /////////////////////////////////////////////////////////////////////////////////////////////////////

    void initializeRobot()
    {
    // Place code here to sinitialize servos to starting positions.
    // Sensors are automatically configured and setup by ROBOTC. They may need a brief time to stabilize.

    return;
    }


    /////////////////////////////////////////////////////////////////////////////////////////////////////
    //
    // Main Task
    //
    // The following is the main code for the tele-op robot operation. Customize as appropriate for
    // your specific robot.
    //
    // Game controller / joystick information is sent periodically (about every 50 milliseconds) from
    // the FMS (Field Management System) to the robot. Most tele-op programs will follow the following
    // logic:
    // 1. Loop forever repeating the following actions:
    // 2. Get the latest game controller / joystick settings that have been received from the PC.
    // 3. Perform appropriate actions based on the joystick + buttons settings. This is usually a
    // simple action:
    // * Joystick values are usually directly translated into power levels for a motor or
    // position of a servo.
    // * Buttons are usually used to start/stop a motor or cause a servo to move to a specific
    // position.
    // 4. Repeat the loop.
    //
    // Your program needs to continuously loop because you need to continuously respond to changes in
    // the game controller settings.
    //
    // At the end of the tele-op period, the FMS will autonmatically abort (stop) execution of the program.
    //
    /////////////////////////////////////////////////////////////////////////////////////////////////////

    task main()
    {
    initializeRobot();


    while (true)
    {
    getJoystickSettings(joystick);
    if(joy1Btn(4) == 1) // If the right analog stick's Y-axis readings are either above or below the threshold...
    {
    motor[motorD] = 50;
    motor[motorE] = 50;
    // ...the right motor is assigned a power level equal to the right analog stick's Y-axis reading.
    }
    else // Else the readings are within the threshold, so
    {
    motor[motorD] = 0;
    motor[motorE] = 0;
    // ...the right motor is stopped with a power level of 0.
    }

    if(joy1Btn(3) == 1) // If the right analog stick's Y-axis readings are either above or below the threshold...
    {
    motor[motorE] = 50;
    // ...the right motor is assigned a power level equal to the right analog stick's Y-axis reading.
    }
    else // Else the readings are within the threshold, so
    {
    motor[motorE] = 0;
    // ...the right motor is stopped with a power level of 0.
    }

    if(joy1Btn(1) == 1) // If the right analog stick's Y-axis readings are either above or below the threshold...
    {
    motor[motorD] = 50;
    // ...the right motor is assigned a power level equal to the right analog stick's Y-axis reading.
    }
    else // Else the readings are within the threshold, so
    {
    motor[motorD] = 0;
    }
    // ...the right motor is stopped with a power level of 0.\

    if(joy1Btn(2) == 1) // If the right analog stick's Y-axis readings are either above or below the threshold...
    {
    motor[motorD] = -50;
    motor[motorE] = -50;
    // ...the right motor is assigned a power level equal to the right analog stick's Y-axis reading.
    }
    else // Else the readings are within the threshold, so
    {
    motor[motorD] = 0;
    motor[motorE] = 0;
    // ...the right motor is stopped with a power level of 0.
    }

    *
    if(joy1Btn(5) == 1)
    {
    motor[motorA] = 50;
    wait1Msec(2700);
    }
    else
    {
    motor[motorA] = 0;
    wait1Msec(500);
    }
    }
    }

    // ...the right motor is stopped with a power level of 0.
    ///////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////
    //// ////
    //// Add your robot specific tele-op code here. ////
    //// ////
    ///////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////

    // Insert code to have servos and motors respond to joystick and button values.

    // Look in the ROBOTC samples folder for programs that may be similar to what you want to perform.
    // You may be able to find "snippets" of code that are similar to the functions that you want to
    // perform.

  • #2
    I see part of your problem.
    Originally posted by AvatarSR View Post
    Code:
        if(joy1Btn(4) == 1)     // If the right analog stick's Y-axis readings are either above or below the threshold...
        {
          motor[motorD] = 50;
          motor[motorE] = 50;
         // ...the right motor is assigned a power level equal to the right analog stick's Y-axis reading.
        }
        else                                      // Else the readings are within the threshold, so
        {
          motor[motorD] = 0;
          motor[motorE] = 0;
          // ...the right motor is stopped with a power level of 0.
        }
    joy1Btn(buttonID) returns true if button buttonID is pressed. For example, if you had:

    Code:
    if (joystick.joy1Btn(1)) {
    //stuff
    }
    the "stuff" would only run if button #1 was pressed.

    So, that's one place where I think your problem is coming from.

    You should know that to read from joysticks, you use:
    joystick.joy1_y1 (joystick 1 y1)
    joystick.joy2_x2 (joystick 1 x2)
    and so on and so forth, changing the numbers/x/y based on which joystick.

    Please let me know if you have more questions.
    Basement Lions FTC Robotics Team #4236: Founding Member and Leader
    Space Lions FTC Robotics Team #7890: Mentor (sister team to 4326)

    Basement Lions and Space Lions Website

    Comment


    • #3
      I think you may have confused joystick buttons with joystick analog sticks. The joy1Btn(n) function returns a number depending on the state (pressed, unpressed) of the button in question. The values for the analog sticks are accessed via the variables joystick.joy1_x1, joystick.joy1_y1, joystick.joy1_x2, joystick.joy1_y2, where the first number refers to the controller number and the second number refers to the stick - (x1, y1) for the left stick and (x2, y2) for the right. I'm also not sure what you're trying to do near the end. I believe the asterisk at the beginning of that line is a typo (the program won't compile with it there), and you might want to take another look at this statement:
      Code:
      if(joy1Btn(5) == 1)
      {
         motor[motorA] = 50;
         wait1Msec(2700);
      }
      else
      {
         motor[motorA] = 0;
         wait1Msec(500);
      }
      When they're reached, those wait1Msec commands will stop the execution of the main while loop for the duration specified; if you press button 5, the rest of the code won't be executed for 2.7 seconds while motorA runs. And since you have an else statement, the program will wait for 0.5 seconds regardless.

      Try removing the two wait1Msec commands and run the code; it should work, if you use the numbered buttons on the controllers, rather than the analog sticks. If it still doesn't work, there's probably something wrong in your wiring setup.

      If you want to try with the analog sticks, test this fairly standard driving program. I'm assuming that motorE is right and motorD is left.
      Code:
      #pragma config(Hubs, S1, HTMotor, HTServo, none, none)
      #pragma config(Sensor, S1, , sensorI2CMuxController)
      #pragma config(Motor, mtr_S1_C1_1, motorD, tmotorTetrix, openLoop)
      #pragma config(Motor, mtr_S1_C1_2, motorE, tmotorTetrix, openLoop, reversed)
      #pragma config(Servo, srvo_S1_C2_1, servo1, tServoStandard)
      #pragma config(Servo, srvo_S1_C2_2, servo2, tServoStandard)
      #pragma config(Servo, srvo_S1_C2_3, servo3, tServoNone)
      #pragma config(Servo, srvo_S1_C2_4, servo4, tServoNone)
      #pragma config(Servo, srvo_S1_C2_5, servo5, tServoNone)
      #pragma config(Servo, srvo_S1_C2_6, servo6, tServoNone)
      //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
      
      
      #define THRESHOLD 15
      
      
      #include "JoystickDriver.c" //Include file to "handle" the Bluetooth messages.
      
      
      void initializeRobot()
      {
         return;
      }
      
      
      task main()
      {
         initializeRobot();
         
         waitForStart();
         
         while (true)
         {
            getJoystickSettings(joystick);
            
            if(abs(joystick.joy1_y2) > THRESHOLD) // If the right analog stick's Y-axis readings are either above or below the threshold...
               motor[motorE] = joystick.joy1_y2;  // Power the right motor: proportional to analog stick value.
            else
               motor[motorE] = 0; // Otherwise, stop it.
      
      
            if(abs(joystick.joy1_y1) > THRESHOLD) // If the left analog stick's Y-axis readings are either above or below the threshold...
               motor[motorD] = joystick.joy1_y1;  // Power the left motor: proportional to analog stick value.
            else
               motor[motorD] = 0; // Otherwise, stop it.
         }
      }
      EDIT: Ninja'd by reisst (I probably should have refreshed the page after waiting so long to hit submit) as far as the joy1Btn() vs. joystick.joy1_y1 thing goes, but I think you get the point.
      Last edited by Sparbots; 10-21-2013, 02:49 AM.

      Comment


      • #4
        Sparbots and reisst are absolutely spot on in their points. In addition, you may want take a look at your if-else structures. As of now, the only one that will work is the last one, for button 2:
        Code:
        if(joy1Btn(2) == 1) // If the right analog stick's Y-axis readings are either above or below the threshold...
        {
          motor[motorD] = -50;
          motor[motorE] = -50;
          // ...the right motor is assigned a power level equal to the right analog stick's Y-axis reading.
        }
        else // Else the readings are within the threshold, so
        {
          motor[motorD] = 0;
          motor[motorE] = 0;
          // ...the right motor is stopped with a power level of 0.
        }
        As long as button 2 is not pressed, the power of both motors will be set to 0 and they will go nowhere. If you want to use the button-pressing method and not the thumbstick method, you should combine your if-else statements together, like the following:
        Code:
        if(Condition A)
        {
          // Make the motors do one thing
        }
        else if(Condition B)
        {
          // Make the motors do another thing
        }
        ... Insert as many else if statements as you need here ...
        else
        {
          // Turn off the motors
          motor[motorD] = 0;
          motor[motorE] = 0;
        }
        Burning Lights Programming
        FLL Team 341 Brick Chick'N Boys - Programmer (2009-2010)
        FLL Team 263 Brainy Bricks - Programmer (2010-2011)
        FLL Team 5028 Fellowship of the Brick - Youth Mentor (2011-2012)
        FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
        FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
        FTC Team 7468 Blue Chariots of Fire - Mentor/Coach (2014-2017)

        Comment

        Working...
        X
        😀
        🥰
        🤢
        😎
        😡
        👍
        👎