#pragma config(Hubs, S1, HTMotor, HTMotor, HTMotor, none) #pragma config(Sensor, S1, , sensorI2CMuxController) #pragma config(Sensor, S3, HTIRS2, sensorI2CCustom) #pragma config(Motor, mtr_S1_C1_1, motorD, tmotorTetrix, openLoop, encoder) #pragma config(Motor, mtr_S1_C1_2, motorE, tmotorTetrix, openLoop, encoder) #pragma config(Motor, mtr_S1_C2_1, motorF, tmotorTetrix, openLoop, encoder) #pragma config(Motor, mtr_S1_C2_2, motorG, tmotorTetrix, openLoop, encoder) #pragma config(Motor, mtr_S1_C3_1, motorH, tmotorTetrix, openLoop) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// /*---------------------------------------------------------------------------------------------------------------------------------------------------*/ //Notes / robot set up //ALL DRIVE MOTORS HAVE ENCODERS /*--------------------------------------------------------------------------------------------------------------------------------------------------- |Robot Laid Out Like This ----------------------------- D / \ F | | | | | | | | | | | | E \ / G ----------------------------- /*--------------------------------------------------------------------------------------------------------------------------------------------------- //READ BELOW FIRST!!!!!!!!!!!!!!!!! /*NOTE: EVERYTHING IN GREEN COLOR FONT IS A NOTE & THE ROBOT IGNORES. NOTES EITHER FOLLOW 2 SLASHES (//) AND LAST FOR THAT LINE OF CODE OR FOLLOW A SLASH AND A STAR (/*) AND LAST UNTIL IT APPEARS IN THE OPPOSITE ORDER (*/) /*--------------------------------------------------------------------------------------------------------------------------------------------------- controller 1 (plugged in to the NXT) is the 1st controler, contorls 2 drive motors controller 2 (plugged in to Controler 1) is the 2nd controler, controls the other 2 drive motors controller 3 (plugged in to Controler 2) is the 3rd controler, controller 4 (plugged in to Controler 3) is the 4th controler, RobotC will Automatically configure motors & sensors to configure motors, go to the Robot Menu & select Motors and Sensors Setup*/ /*---------------------------------------------------------------------------------------------------------------------------------------------------*/ //program startup #include "JoystickDriver.c" //IMPORTANT// includes the Code written to allow you to control the robot with a remote control void initializeRobot() //IMPORTANT// starts the Robot for autonomous { //starts autonomous return; //IMPORTANT// returns the robot to this (TeleOp) program after autonomous is over } //ends autonomous /*---------------------------------------------------------------------------------------------------------------------------------------------------*/ //task main task main() //IMPORTANT// everything in Task Main is what the program is written to do { //starts task main (TeleOp) initializeRobot(); //IMPORTANT// starts the robot for teleop waitForStart(); //IMPORTANT// waits for the start of the TeleOp period /*---------------------------------------------------------------------------------------------------------------------------------------------------*/ //int statements int x1 = 0; //sets the initial value of the x axis of the left stick on joystick 1 to 0 int y1 = 0; //sets the initial value of the y axis of the left stick on joystick 1 to 0 int x2 = 0; //sets the initial value of the x axis of the right stick on joystick 1 to 0 int threshold = 15; //sets the value of the dead zone on the controler int scale = 2; /*sets the value of the scale which is the divisor for slow opperation (created so we can change one value instead of 4 if needed)*/ int motorDVal = 0; //sets the initial value of motorD to 0 int motorEVal = 0; //sets the initial value of motorE to 0 int motorFVal = 0; //sets the initial value of motorF to 0 int motorGVal = 0; //sets the initial value of motorG to 0 //TO MATCH THE CONTORLLER IMPUTS (IMPORTANT FOR LATER) /*---------------------------------------------------------------------------------------------------------------------------------------------------*/ //repeat forever while (true) //will repeat everything inside of it until the end of the match { getJoystickSettings(joystick); //gets the joystick settings so the robot knows what imputs the human is making with the remote /*---------------------------------------------------------------------------------------------------------------------------------------------------*/ //if statements //create threshold for x1 axis if(abs(joystick.joy1_x1) > threshold) //if the absolute value of joystick 1, left stick, x-axis is greater than the threshold { x1 = joystick.joy1_x1; //robot will move } else //if the absolute value of joystick 1, left stick, x-axis is less than the threshold { x1 = 0; //robot will NOT move } //create threshold for y1 axis if(abs(joystick.joy1_y1) > threshold) //if the absolute value of joystick 1, left stick, y-axis is greater than the threshold { y1 = joystick.joy1_y1; //robot will move } else //if the absolute value of joystick 1, left stick, y-axis is less than the threshold { y1 = 0; //robot will NOT move } //create threshold for x2 axis if(abs(joystick.joy1_x2) > threshold) //if the absolute value of joystick 1, right stick, x-axis is greater than the threshold { x2 = joystick.joy1_x2; //robot will move } else //if the absolute value of joystick 1, right stick, x-axis is less than the threshold { x2 = 0; //robot will NOT move } /*---------------------------------------------------------------------------------------------------------------------------------------------------*/ //final math and running statements //final math that allows each motor to turn independantly motorDVal = -y1 - x1 - x2; //-(joy1_y1) - (joy1_x1) - (joy1_x2) = the final value of motor D motorEVal = -y1 + x1 - x2; //-(joy1_y1) + (joy1_x1) - (joy1_x2) = the final value of motor E motorFVal = y1 - x1 - x2; //(joy1_y1) - (joy1_x1) - (joy1_x2) = the final value of motor F motorGVal = y1 + x1 - x2; //(joy1_y1) + (joy1_x1) - (joy1_x2) = the final value of motor G //slow-motion if(joy1Btn(6)) //if button 6 on Joystick 1 is pressed { motorDVal = motorDVal / scale; //the final value of motorD is divided by the scale motorEVal = motorEVal / scale; //the final value of motorE is divided by the scale motorFVal = motorFVal / scale; //the final value of motorF is divided by the scale motorGVal = motorGVal / scale; //the final value of motorG is divided by the scale } //normal operation motor[motorD] = motorDVal; //motorD will go as fast as the value sent to it motor[motorE] = motorEVal; //motorE will go as fast as the value sent to it motor[motorF] = motorFVal; //motorF will go as fast as the value sent to it motor[motorG] = motorGVal; //motorG will go as fast as the value sent to it motor[motorH] = joystick.joy2_y2 * -1; //motorH controles the ring lifter /*---------------------------------------------------------------------------------------------------------------------------------------------------*/ //end of program } //end of the while statement } //end of the task main statemen