View unanswered posts | View active topics It is currently Fri Aug 22, 2014 9:49 pm






Reply to topic  [ 11 posts ] 
Quick controller Question 
Author Message
Rookie

Joined: Thu Nov 19, 2009 1:21 pm
Posts: 11
Post Quick controller Question
Our team is trying to set up the dual contoller setup. However the robot doesn't respond to the second controller at all. We believe that it isn't so much the syntax of the program, but maybe it is the way we have the program get settings from the driver. right now it is setup to #include "Joystickdriver.c" and then to getjoysticksettings(joystick); do we need another thing to allow control of the other controller. For information it worked fine with just one controller. Thanks.


Mon Jan 11, 2010 8:27 pm
Profile
Rookie
User avatar

Joined: Sat Oct 10, 2009 2:37 pm
Posts: 5
Post Re: Quick controller Question
I am having the same issue. Furthermore adding code such as:

Code:
if(joy2Btn(1)==1)
{
}


causes errors in other parts of my code.


Mon Jan 11, 2010 11:06 pm
Profile
Expert

Joined: Mon Oct 27, 2008 9:59 pm
Posts: 137
Post Re: Quick controller Question
dallasrobotics wrote:
Our team is trying to set up the dual contoller setup. However the robot doesn't respond to the second controller at all. We believe that it isn't so much the syntax of the program, but maybe it is the way we have the program get settings from the driver. right now it is setup to #include "Joystickdriver.c" and then to getjoysticksettings(joystick); do we need another thing to allow control of the other controller. For information it worked fine with just one controller. Thanks.


That is the correct usage.
Are you using the dual joystick setting in the joystick debug window & are you sure both joysticks are registered and working properly?


Tue Jan 12, 2010 9:47 am
Profile
Expert

Joined: Mon Oct 27, 2008 9:59 pm
Posts: 137
Post Re: Quick controller Question
Harry Potter wrote:
I am having the same issue. Furthermore adding code such as:
Code:
if(joy2Btn(1)==1)
{
}

causes errors in other parts of my code.


Can you provide a more specific code example and what types of errors it is giving you?


Tue Jan 12, 2010 9:48 am
Profile
Rookie

Joined: Thu Nov 19, 2009 1:21 pm
Posts: 11
Post Re: Quick controller Question
Yes we have the dual joystick checkboc checked and the second one comes up and responds to controls, meaning it shows the buttons being pressed. But the robot doesn't respond to the controls, and I know that they are programmed for the second one.


Tue Jan 12, 2010 6:18 pm
Profile
Expert

Joined: Mon Oct 27, 2008 9:59 pm
Posts: 137
Post Re: Quick controller Question
dallasrobotics, can you post the code in question?


Tue Jan 12, 2010 6:31 pm
Profile
Rookie
User avatar

Joined: Wed Feb 25, 2009 7:00 pm
Posts: 10
Post Re: Quick controller Question
Harry Potter wrote:
I am having the same issue. Furthermore adding code such as:

Code:
if(joy2Btn(1)==1)
{
}


causes errors in other parts of my code.


That's because it's not the right syntax. joy2btn(1) tests for the button in itself. From "JoystickDriver.c":
Code:
bool joy1Btn(int btn)
{   return ((joystick.joy1_Buttons & (1 << (btn - 1))) != 0);  }
bool joy2Btn(int btn)
{   return ((joystick.joy2_Buttons & (1 << (btn - 1))) != 0);  }

Code:
if(joy1Btn(2))
Will work just fine. I don't know if that's part of your problem, dallasrobotics.

_________________
--Nathan


Wed Jan 13, 2010 7:25 pm
Profile
Expert

Joined: Mon Oct 27, 2008 9:59 pm
Posts: 137
Post Re: Quick controller Question
Code:
if(joy2Btn(1)==1)
is equivalent to
Code:
if(joy2Btn(1)==true)
is equivalent to
Code:
if(joy2Btn(1))

The syntax is fine, although I personally prefer the simplified style in nender's example.


Thu Jan 14, 2010 10:26 am
Profile
Rookie

Joined: Thu Nov 19, 2009 1:21 pm
Posts: 11
Post Re: Quick controller Question
here it is it's long.

#pragma config(Hubs, S1, HTMotor, HTServo, none, none)
#pragma config(Hubs, S2, HTMotor, none, none, none)
#pragma config(Motor, mtr_S1_C1_1, motorLeft, tmotorNormal, openLoop, reversed)
#pragma config(Motor, mtr_S1_C1_2, motorRight, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S2_C1_1, thrower, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S2_C1_2, motorG, tmotorNormal, openLoop)
#pragma config(Servo, srvo_S1_C2_1, launcher, tServoNormal)
#pragma config(Servo, srvo_S1_C2_2, scoop, tServoNormal)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#include "JoystickDriver.c"
task main()
{
while(true)
{
getJoystickSettings(joystick);

if(joy2Btn(6) != 1) // driver control
{
if(joy2Btn(5) == 1)
{
servo[launcher] = 206;
servoChangeRate[launcher] = 0;
}

if(joy2Btn(7) == 1)
{
servo[launcher] = 242;
servoChangeRate[launcher] = 0;
}

while(joy1Btn(5) != 1) // without boost
{
while(joy1Btn(7) != 1) //normal control
{
//single joystick control with claw as front
motor[motorLeft] = (((joystick.joy1_y1*25)/-127) + (joystick.joy1_x1*25)/-127);
motor[motorRight] = (((joystick.joy1_y1*25)/-127) - (joystick.joy1_x1*25)/-127);

//scoop controls
if(joy1Btn(1) == 1)
{
servo[scoop] = 0;
servoChangeRate[scoop] = 0;
}

if(joy1Btn(2) == 1)
{
servo[scoop] = 255;
servoChangeRate[scoop] = 0;
}
}

while(joy1Btn(7) == 1)
{
//single joystick control with shooter as front
motor[motorLeft] = (((joystick.joy1_y1*25)/127) - (joystick.joy1_x1*25)/127);
motor[motorRight] = (((joystick.joy1_y1*25)/127) + (joystick.joy1_x1*25)/127);
}
}

{

while(joy1Btn(5) == 1) // with boost
{
//single joystick control with claw as front
motor[motorLeft] = (((joystick.joy1_y1*50)/-127) + (joystick.joy1_x1*50)/-127);
motor[motorRight] = (((joystick.joy1_y1*50)/-127) - (joystick.joy1_x1*50)/-127);

// Scoop disabled buring boost
}
}

if(joy2Btn(6) == 1) // shooter control
{
motor[thrower] = ((joystick.joy2_y2*100)/-127);

if(joy2Btn(5) == 1)
{
servo[launcher] = 206;
servoChangeRate[launcher] = 0;
}

if(joy2Btn(7) == 1)
{
servo[launcher] = 255;
servoChangeRate[launcher] = 0;
}


while(joy1Btn(7) != 1)
{
//single joystick control with shooter as front
motor[motorLeft] = (((joystick.joy2_y1*25)/127) - (joystick.joy2_x1*25)/127);
motor[motorRight] = (((joystick.joy2_y1*25)/127) + (joystick.joy2_x1*25)/127);

}

while(joy1Btn(7) == 1)
{
//single joystick control with shooter as front
motor[motorLeft] = (((joystick.joy1_y1*25)/127) + (joystick.joy1_x1*25)/127);
motor[motorRight] = (((joystick.joy1_y1*25)/127) - (joystick.joy1_x1*25)/127);
}
}

}
}
}


Thu Jan 14, 2010 6:27 pm
Profile
Expert

Joined: Mon Oct 27, 2008 9:59 pm
Posts: 137
Post Re: Quick controller Question
I'm going to assume that most of your issues are a direct result of misusing while loops when you likely wanted to use a simple if condition. Remember that the code within the body of the while construct will be the only code executed (in a rapid loop) until the condition in the while statement becomes false.
So for example, if you have two joysticks and one of your while loops is run if a button on joystick 1 is not pressed, then nothing else in your code (which may do things based on input from joystick 2) will be executed until that button on the first joystick is pressed.

I see exactly that scenario in the snippet below. Notice how nothing else in your code will ever get executed until button 7 on joystick 1 is pressed. There are numerous cases of this in your code and I suspect you are getting trapped up in them.
Code:
while(joy1Btn(7) != 1) //normal control
{
   //single joystick control with claw as front
   motor[motorLeft] = (((joystick.joy1_y1*25)/-127) + (joystick.joy1_x1*25)/-127);
   motor[motorRight] = (((joystick.joy1_y1*25)/-127) - (joystick.joy1_x1*25)/-127);

   //scoop controls
   if(joy1Btn(1) == 1)
   {
      servo[scoop] = 0;
      servoChangeRate[scoop] = 0;
   }

   if(joy1Btn(2) == 1)
   {
      servo[scoop] = 255;
      servoChangeRate[scoop] = 0;
   }
}


Here is your same code with the while loops switched to if/else conditions and a portion of your drive-train control removed from the shooter control block at the bottom (it appeared to be in multiple places?):

Code:
#pragma config(Hubs, S1, HTMotor, HTServo, none, none)
#pragma config(Hubs, S2, HTMotor, none, none, none)
#pragma config(Motor, mtr_S1_C1_1, motorLeft, tmotorNormal, openLoop, reversed)
#pragma config(Motor, mtr_S1_C1_2, motorRight, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S2_C1_1, thrower, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S2_C1_2, motorG, tmotorNormal, openLoop)
#pragma config(Servo, srvo_S1_C2_1, launcher, tServoNormal)
#pragma config(Servo, srvo_S1_C2_2, scoop, tServoNormal)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#include "JoystickDriver.c"
task main()
{
   while(true)
   {
      getJoystickSettings(joystick);

      if(!joy2Btn(6)) // driver control
      {
         if(joy2Btn(5))
         {
            servo[launcher] = 206;
            servoChangeRate[launcher] = 0;
         }
         else if(joy2Btn(7))
         {
            servo[launcher] = 242;
            servoChangeRate[launcher] = 0;
         }

         if(!joy1Btn(5)) // without boost
         {
            if(!joy1Btn(7)) //normal control
            {
               //single joystick control with claw as front
               motor[motorLeft] = (((joystick.joy1_y1*25)/-127) + (joystick.joy1_x1*25)/-127);
               motor[motorRight] = (((joystick.joy1_y1*25)/-127) - (joystick.joy1_x1*25)/-127);

               //scoop controls
               if(joy1Btn(1))
               {
                  servo[scoop] = 0;
                  servoChangeRate[scoop] = 0;
               }
               else if(joy1Btn(2))
               {
                  servo[scoop] = 255;
                  servoChangeRate[scoop] = 0;
               }
            }
            else
            {
               //single joystick control with shooter as front
               motor[motorLeft] = (((joystick.joy1_y1*25)/127) - (joystick.joy1_x1*25)/127);
               motor[motorRight] = (((joystick.joy1_y1*25)/127) + (joystick.joy1_x1*25)/127);
            }
         }
         else // with boost
         {
            //single joystick control with claw as front
            motor[motorLeft] = (((joystick.joy1_y1*50)/-127) + (joystick.joy1_x1*50)/-127);
            motor[motorRight] = (((joystick.joy1_y1*50)/-127) - (joystick.joy1_x1*50)/-127);

            // Scoop disabled buring boost
         }

         if(joy2Btn(6)) // shooter control
         {
            motor[thrower] = ((joystick.joy2_y2*100)/-127);

            if(joy2Btn(5))
            {
               servo[launcher] = 206;
               servoChangeRate[launcher] = 0;
            }
            else if(joy2Btn(7))
            {
               servo[launcher] = 255;
               servoChangeRate[launcher] = 0;
            }
                  
         }
      }
   }
}


Notice how much simpler this is already. I'd suggest changing all your nested while statements out with if statements (not the outer while(true) statement) and try troubleshooting from there.

Best of luck.
-l0jec


Fri Jan 15, 2010 1:48 pm
Profile
Rookie

Joined: Thu Nov 19, 2009 1:21 pm
Posts: 11
Post Re: Quick controller Question
well we were trying to do a intricate control scheme and then we discovered that it would be much simpler if we just left one controller to moving and one to shooting. I simplified it and now it works. Thanks for helping.


Fri Jan 15, 2010 7:37 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 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.