Announcement

Collapse
No announcement yet.

Controller issue? Programming issue?

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

  • Controller issue? Programming issue?

    Hello everyone.

    We are trying the code you see below to control our robot, it is basically the same code as last year. We know the Samantha module, brick, and wifi are working because it does "Wait for Start" and then when we start it from FCS it enters into TeleOp mode. So they are communicating. The question is why is nothing moving?

    We tried all sorts of different things, and we are really at a loss...

    Might it have something to do with joystickdriver.c ? Is that setup appropiately to communicate to the samantha module, or is it for bluetooth? Or????

    Code:
    #pragma config(Hubs,  S1, HTMotor,  HTServo,  none,     none)
    #pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorNormal, openLoop)
    #pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorNormal, openLoop)
    #pragma config(Servo,  srvo_S1_C2_5,    motorF,                     tServoStandard)
    #pragma config(Servo,  srvo_S1_C2_6,    motorG,                     tServoStandard)
    //*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
    
    #include "JoystickDriver.c"
    
    task main() {
    //  initializeRobot();
      waitForStart();   // wait for start of tele-op phase -- it all works up to here...
      while (true) {
      getJoystickSettings(joystick);
    // ----------------------------------------------------------------------------------------------
    motor[motorD] = joystick.joy1_y1;
    motor[motorE] = joystick.joy1_y2;
    // ----------------------------------------------------------------------------------------------
         if(joystick.joy1_TopHat == 4 || joystick.joy2_TopHat == 4)
        {
          motor[motorF] = 100;
        }
        else
        {
         motor[motorF] = 0;
       }
    // ----------------------------------------------------------------------------------------------
         if(joystick.joy1_TopHat == 6 || joystick.joy2_TopHat == 6) {
          motor[motorF] = -100;
        }
        else {
         motor[motorF] = 0;
       }
    // ----------------------------------------------------------------------------------------------
         if(joystick.joy1_TopHat == 5 || joystick.joy2_TopHat == 5) {
          motor[motorG] = 100;
        }
        else {
         motor[motorG] = 0;
       }
    // -----------------------------------------------------------------------------------------------
         if(joystick.joy1_TopHat == 7 || joystick.joy2_TopHat == 7) {
          motor[motorG] = -100;
        }
        else {
         motor[motorG] = 0;
       }
     }
    }
    Last edited by hsetigers; 10-15-2010, 12:56 PM. Reason: code update - still nonworking

  • #2
    to me there doesn't appear to be any specific errors in your software. I would recommend inspecting your motor controller setup to see if they match up. I noticed that your motor/servo controller daisy chain was setup in the pragma statements for port 4 of your NXT

    Comment


    • #3
      thanks for the reply, we updated the code - changed it in org. post. now when we start it from the FCS it actually makes a nice buzzing sound like it is activated - so I hope we are getting closer to the fix...

      we did put it back on port one too.

      Comment


      • #4
        Actually, your definitions call out motorG (and MotorF) to be servos... thus your code should be referencing the servo[] array, not the motor array.

        Comment


        • #5
          Try commenting out the top hat controls, see if it works driving around regularly. If it doesn't, then it's a more complicated problem. If it works, then add each of the top hat servo controls one at a time.
          SAY-WATT.ORG

          Comment


          • #6
            there are a few problems with the code.

            First,
            #pragma config(Hubs, S1, HTMotor, HTServo, none, none)
            #pragma config(Servo, srvo_S1_C2_5, motorF, tServoStandard)

            <snip>

            motor[motorF] = 100;
            cannot work...

            you probably mean either
            Code:
            #pragma config(Hubs,  S1, HTMotor,  HTMotor,  none,     none)
            #pragma config(Motor,  mtr_S1_C2_1,     motorF,        tmotorNormal, openLoop)
            <snip>
            motor[motorF] = 100;
            or more likely

            Code:
            #pragma config(Hubs,  S1, HTMotor,  HTServo,  none,     none)
            #pragma config(Servo,  srvo_S1_C2_5,    motorF,                     tServoStandard)
            
            <snip>
            
            servo[motorF] = 100;

            Second
            Your "if" statements are not exclusive. Loop through the code, one line at a time and you will see that when you press button 4, the code is telling the servo to jump to position 100 and then because button 6 is not pressed, to jump back to 0, and then since its in a loop, the next scan, jump to 100, then back to 0... etc

            Hope that helps!

            Also note that the servos position themselves based on values from 0 to 255. the buzzing you hear might be the servo pushing the wrong way... If you start your servo pointed at position 128, and that position is with an arm up against a wall, then you have a 50/50 chance that the servo will be pushing into the wall when you give it a position command of 0.

            Comment

            Working...
            X