View unanswered posts | View active topics It is currently Tue Nov 12, 2019 7:25 pm






Reply to topic  [ 2 posts ] 
Is there something wrong with our code? 
Author Message
Rookie

Joined: Fri Jan 09, 2015 8:35 pm
Posts: 1
Post Is there something wrong with our code?
Our motors won't move at all! Is there something we did wrong??

#pragma platform(NXT) //Setting the platform for the program to NXT
#pragma competitionControl (competition) //Setting the control to competition

// Need to program motors and servos to the hubs and controllers
#pragma config(Hubs, S1, HTMotor, none, none, none) // *REQUIRES CLARIFICATION* Need to program the hub
#pragma config(Motor, port1, motorA, tmotorNXT, openLoop) // This line sets the "pulley motor" as motorA
#pragma config(Motor, port2, motorB, tmotorNXT, openLoop) // This line sets the motor on the *left* frame as motorB
#pragma config(Motor, port3, motorC, tmotorNXT, openLoop) // This line sets the motor on the *right* frame as motorC
//#pragma config(Servo, port4, servo1, tServoStandard) // This line sets the servo

task main()
{

bool autonomous = false; // *DRIVER CONTROLLED PROGRAM ONLY* Set this to false ONLY for driverControlled program

if (autonomous) {

motor[motorC] = 100; // Motor C is run at a power level of 100.
motor[motorB] = -100; // Motor B is run at a power level of 100.
wait1Msec(6000); // The program waits 6000 milliseconds (6 seconds) before running further code
motor[motorC] = 0; // Motor C is being stopped
motor[motorB] = 0; // Motor B is being stopped
}
else {
while(true) {
getJoystickSettings(joystick);

/*
The following code assumes the following motor configurations:
motorA = pulley;
motorB = leftMotor;
motorC = rightMotor;
servo1 = gate;
*/

if((abs(joystick.joy1_y1) >= 10) || (abs(joystick.joy1_x1) >= 10)) {
motor[motorB] = joystick.joy1_y1;
motor[motorC] = -joystick.joy1_y1;
if(joystick.joy1_x1 <= -10)
motor[motorB] -= abs(joystick.joy1_x1);
else if(joystick.joy1_x1 >= 10)
motor[motorC] += abs(joystick.joy1_x1);
}
else {
motor[motorB] = 0;
motor[motorC] = 0;
}

if(abs(joystick.joy1_y2) >= 10) {
motor[motorA] = joystick.joy1_y2;
}
else {
motor[motorA] = 0;
}

if(joy1Btn(8)) {
servo[servo1] = 40;

}
else {
servo[servo1] = 0;
}
}
}
}


Fri Jan 09, 2015 8:47 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Post Re: Is there something wrong with our code?
This is your code with proper indentation. The code doesn't make too much sense. You may want to tell us what you are expecting your code to do.
Code:
#pragma platform(NXT) //Setting the platform for the program to NXT
#pragma competitionControl (competition) //Setting the control to competition

// Need to program motors and servos to the hubs and controllers
#pragma config(Hubs, S1, HTMotor, none, none, none) // *REQUIRES CLARIFICATION* Need to program the hub
#pragma config(Motor, port1, motorA, tmotorNXT, openLoop) // This line sets the "pulley motor" as motorA
#pragma config(Motor, port2, motorB, tmotorNXT, openLoop) // This line sets the motor on the *left* frame as motorB
#pragma config(Motor, port3, motorC, tmotorNXT, openLoop) // This line sets the motor on the *right* frame as motorC
//#pragma config(Servo, port4, servo1, tServoStandard) // This line sets the servo

task main()
{
    bool autonomous = false; // *DRIVER CONTROLLED PROGRAM ONLY* Set this to false ONLY for driverControlled program

    if (autonomous) {
        motor[motorC] = 100; // Motor C is run at a power level of 100.
        motor[motorB] = -100; // Motor B is run at a power level of 100.
        wait1Msec(6000); // The program waits 6000 milliseconds (6 seconds) before running further code
        motor[motorC] = 0; // Motor C is being stopped
        motor[motorB] = 0; // Motor B is being stopped
    }
    else {
        while(true) {
            getJoystickSettings(joystick);

 /*
 The following code assumes the following motor configurations:
 motorA = pulley;
 motorB = leftMotor;
 motorC = rightMotor;
 servo1 = gate;
 */

            if((abs(joystick.joy1_y1) >= 10) || (abs(joystick.joy1_x1) >= 10)) {
                motor[motorB] = joystick.joy1_y1;
                motor[motorC] = -joystick.joy1_y1;
                if(joystick.joy1_x1 <= -10)
                    motor[motorB] -= abs(joystick.joy1_x1);
                else if(joystick.joy1_x1 >= 10)
                    motor[motorC] += abs(joystick.joy1_x1);
            }
            else {
                motor[motorB] = 0;
                motor[motorC] = 0;
            }

            if(abs(joystick.joy1_y2) >= 10) {
                motor[motorA] = joystick.joy1_y2;
            }
            else {
                motor[motorA] = 0;
            }

            if(joy1Btn(8)) {
                servo[servo1] = 40;

            }
            else {
                servo[servo1] = 0;
            }
        }
    }
}


Sat Jan 10, 2015 4:53 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.