View unanswered posts | View active topics It is currently Sun Nov 17, 2019 8:15 am






Reply to topic  [ 2 posts ] 
Help debug my code? 
Author Message
Rookie

Joined: Tue Nov 11, 2014 7:19 pm
Posts: 2
Post Help debug my code?
I marked it up so hopefully it will be easier to read :3
EDIT: I forgot to add that the robot's wheels will not move when the controller is active.
Code:
#pragma config(Hubs,  S1, HTMotor,  none,     none,     none)
#pragma config(Hubs,  S2, HTMotor,  none,     none,     none)
#pragma config(Hubs,  S3, HTServo,  none,     none,     none)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S2_C1_1,     motorF,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S2_C1_2,     motorG,        tmotorTetrix, openLoop)
#pragma config(Servo,  srvo_S3_C1_1,    servo1,               tServoNone)
#pragma config(Servo,  srvo_S3_C1_2,    servo2,               tServoNone)
#pragma config(Servo,  srvo_S3_C1_3,    servo3,               tServoNone)
#pragma config(Servo,  srvo_S3_C1_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S3_C1_5,    servo5,               tServoNone)
#pragma config(Servo,  srvo_S3_C1_6,    servo6,               tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
int HalfSpeed;
/*

Motor D - Left drive wheel

Motor E - Right drive wheel

Motor F - Vertical slides

Motor G - Spinner

*/



#define DEADZONE 15 //Sets a deadzone so joysticks dont move the robot when idle

//Include JoystickDriver isnt needed anymore ^.^

task main()
{

   waitForStart(); //Waits for a signal from Mission Control to start the programs

   while(true)
   {
      getJoystickSettings(joystick);// refreshes joystick values

      //Half Speed code below

      if(joy1Btn(7)==1)
      {
         HalfSpeed = 1;
      }
      else
      {
         HalfSpeed = 0;
      }

      //Spinner code below
      if(joy2Btn(8)==1) // If right trigger is pressed on the second controller, execute the following code
      {

         motor[motorG] = 75; // Rotate spinner

      }
      else if(joy2Btn(6)==1) // If right trigger is not presses on the second controller, but the right bumper is, execute this code
      {

         motor[motorG] = -75; // Rotate spinner, in reverse

      }
      else // If neither right bumper nor right trigger is pressed, execute the folowing code
      {


         motor[motorG] = 0; // Stops spinner from moving

      }

      //*******************************************************************

      //Start Left Drive function

      if (joystick.joy1_y1 < DEADZONE && joystick.joy1_y1 > -1*DEADZONE) //when the joystick value is in the deadzone,exe
      {
         motor[motorD] = 0;
      }
      else if (HalfSpeed == 1)//checks if the half speed button is held, if so, movement speed is halved
      {
         motor[motorD] = joystick.joy1_y1/2;
      }
      else
      {
         motor[motorD] = joystick.joy1_y1;
      }
      //Start  Right Drive function

      if (joystick.joy1_y2 < DEADZONE && joystick.joy1_y2 > -1*DEADZONE) //when the joystick value is in the deadzone,exe
      {
         motor[motorE] = 0;
      }
      else if (HalfSpeed == 1)//checks if the half speed button is held, if so, movement speed is halved
      {
         motor[motorE] = joystick.joy1_y2/2;
      }
      else
      {
         motor[motorE] = joystick.joy1_y2;
      }
   }
}


Tue Nov 25, 2014 7:39 pm
Profile
Professor
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
Post Re: Help debug my code?
What version of ROBOTC are you using? If you have version 4.26, the joysticks don't work with Natural Language enabled. I'm guessing you have Natural Language enabled, since you didn't have to include JoystickDriver.c. If you're using 4.26, upgrading to 4.27 should fix this.

_________________
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 (2014-2015)
Check out our team website at http://bluechariotsoffire.com/.


Tue Nov 25, 2014 11:40 pm
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.