View unanswered posts | View active topics It is currently Wed Nov 26, 2014 7:08 pm






Reply to topic  [ 4 posts ] 
Prgramming a second joystick 
Author Message
Rookie

Joined: Fri Nov 08, 2013 9:22 pm
Posts: 3
Post Prgramming a second joystick
(I have a feeling this has been asked before, but I couldn't find the topic.)

So, I am a first year on my team, and I have been put to the task of programming the robot.

Anyhow, I am trying to program support for a second joystick. I have tried multiple ways to get it to work, but the first joystick is the only one that works.
When I try to move the robot with the 2nd joystick, nothing happens. :\

Here is what I have put in so far:

Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTMotor,  HTServo)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Sensor, S3,     ,               sensorSONAR)
#pragma config(Sensor, S4,     ,               sensorHiTechnicIRSeeker1200)
#pragma config(Motor,  mtr_S1_C1_1,     lwheel,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     rwheel,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_1,     flag,          tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_2,     blockarm,      tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C3_1,     blockarm2,     tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C3_2,     blocksweeper,  tmotorTetrix, openLoop)
#pragma config(Servo,  srvo_S1_C4_1,    flagarm,              tServoStandard)
#pragma config(Servo,  srvo_S1_C4_2,    autoblock,            tServoStandard)
#pragma config(Servo,  srvo_S1_C4_3,    bucketdoor,           tServoStandard)
#pragma config(Servo,  srvo_S1_C4_4,    liftrobo1,            tServoStandard)
#pragma config(Servo,  srvo_S1_C4_5,    liftrobo2,            tServoStandard)
#pragma config(Servo,  srvo_S1_C4_6,    servo6,               tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"

void initializeRobot()
{
  servo[flagarm] = 25;
}

task main()
{
 int threshold = 10;
 float k = 0.78;
 bool flagBool = false;

 while(true)
  {
    getJoystickSettings(joystick);

    // turn on right drive motor (1)

       if(abs(joystick.joy1_y1) > threshold || abs(joystick.joy1_y1) > abs(joystick.joy2_y1))
    {
        motor[lwheel] = k * joystick.joy1_y1;
    }
    else
    {
      motor[lwheel] = 0;
    }

    // turn on left drive motor (2)

      if(abs(joystick.joy1_y2) > threshold || abs(joystick.joy1_y1) > abs(joystick.joy2_y1))
    {
        motor[rwheel] = -k * joystick.joy1_y2;
    }
    else
    {
       motor[rwheel] = 0;
    }

      //flag raiser

    if(joy1Btn(3)) // extend the flag spinner
    {
       motor(flag) = -100;
    }
    else
    {
       motor(flag) = 0;
    }
    if(joy1Btn(4))
    {
       motor(flag) = 100;
    }
    else
    {
      motor(flag)   = 0;
    }

    //get blocks
//    if()

    //pulley raiser

    if(joy1Btn(6))
    {
       motor[blockarm] = 100;
       motor[blockarm2] = -100;
    }
    else if(joy1Btn(5))
    {
       motor[blockarm] = -35;
       motor[blockarm2] = 35;
    }
    else
    {
       motor[blockarm] = 0;
       motor[blockarm2] = 0;
    }

    if(joy1Btn(7))
    {
       motor[blocksweeper] = 100;
    }
    else
    {
       motor[blocksweeper] = 0;
    }
    if(joy1Btn(8))
    {
       motor[blocksweeper] = -75;
    }
    else
    {
       motor[blocksweeper] = 0;
    }

    //activate flag raiser

    while(joy1Btn(1))
      {
         if(!flagBool)
        {
           servo[flagarm] = 255;
        }
         if(flagBool)
         {
            servo[flagarm] = 25;
           }
      }
     flagBool = !flagBool;
    wait10Msec(10);
    }



    //Joystick 2



      if(abs(joystick.joy2_y1) > threshold || abs(joystick.joy2_y1) > abs(joystick.joy1_y1))
    {
        motor[lwheel] = k * joystick.joy2_y1;
    }
    else
    {
      motor[lwheel] = 0;
    }

    // turn on left drive motor (2)

      if(abs(joystick.joy2_y2) > threshold || abs(joystick.joy2_y2) > abs(joystick.joy1_y2))
    {
        motor[rwheel] = -k * joystick.joy2_y2;
    }
    else
    {
       motor[rwheel] = 0;
    }

    if(joy1Btn(3))
    {
       motor(flag) = -100;
    }
    if(joy1Btn(4))
    {
       motor(flag) = 100;
    }

    if(joy2Btn(6))
    {
       motor[blockarm] = 100;
       motor[blockarm2] = -100;
    }
    else if(joy2Btn(5))
    {
       motor[blockarm] = -35;
       motor[blockarm2] = 35;
    }
    else
    {
       motor[blockarm] = 0;
       motor[blockarm2] = 0;
    }
    if(joy2Btn(1))
    {
       servo[bucketdoor] = 255;
    }
    else
    {
       servo[bucketdoor] = 0;
    }
    if(joy2Btn(2))
    {
       servo[bucketdoor] = 0;
    }
    else
    {
       servo[bucketdoor] = 255;
    }
    if(joy2Btn(7))
    {
       servo[liftrobo1] = 255;
       servo[liftrobo2] = 255;
    }
    if(joy2Btn(8))
    {
       servo[liftrobo1] = 0;
       servo[liftrobo2] = 0;
    }
  }


I am mostly concerned why the second joystick isn't moving at all.

The program is attached.

Thanks in advance. :)


Attachments:
File comment: This is the uploaded teleop program that needs fixing.
DriverCont4.0.c [4.31 KiB]
Downloaded 143 times
Fri Dec 27, 2013 5:55 pm
Profile
Rookie

Joined: Fri Nov 08, 2013 9:22 pm
Posts: 3
Post Re: Prgramming a second joystick
Okay, One brace wasn't closed, and the second controller works now, but very very jerkily, and sometimes not at all.


Fri Dec 27, 2013 7:35 pm
Profile
Expert
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 188
Post Re: Prgramming a second joystick
I believe that behavior would be because your drive values set by the first and second controllers are clobbering each other. If the joysticks on both controllers are being pushed, then the drive motor power will be alternating back and forth between the two values. If the joysticks are being pushed on only one controller, then the motor power will be alternating back and forth between the power value you want and zero. This is because your joystick code for the two controllers is in two separate if statements. My recommendation would be to decide which controller you want to be the primary drive controller, then combine the two if statements into one in an if-else if-else statement, like this:
Code:
// turn on right drive motor (1)
if(abs(joystick.joy1_y1) > threshold || abs(joystick.joy1_y1) > abs(joystick.joy2_y1))
{
  // Primary control
  motor[lwheel] = k * joystick.joy1_y1;
}
else if(abs(joystick.joy2_y1) > threshold || abs(joystick.joy2_y1) > abs(joystick.joy1_y1))
{
  // Secondary control
  motor[lwheel] = k * joystick.joy2_y1;
 }
 else
 {
  // Stop!
   motor[lwheel] = 0;
 }


Also, be sure to copy this for the right wheel.

_________________
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 Dec 31, 2013 11:19 am
Profile
Rookie

Joined: Fri Nov 08, 2013 9:22 pm
Posts: 3
Post Re: Prgramming a second joystick
I suppose an if else would work... Well, I'll give it a try after winter break. I believe that it will work, so thank you so much! Good luck to all. :)


Tue Dec 31, 2013 2:14 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: Jarrod FTC 8737 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.