View unanswered posts | View active topics It is currently Mon Nov 24, 2014 11:14 am






Reply to topic  [ 7 posts ] 
HELP!!!!!! 
Author Message
Rookie

Joined: Tue Feb 01, 2011 8:09 pm
Posts: 6
Post HELP!!!!!!
We are having major issues with our programming and would appreciate help
The problems we are having are:
First, we don't know how to make 2 controllers work. We need them to work together.
We have a screwy servo movement, sometimes we have to use a shoulder button, or a combo of shoulder buttons to work them, sometimes they won't work at all. We want them to move continusly when we press a certain button on controller 2 and stop when it is relased. (motor control will be on controller1)
Please fix program as needed.

task main()
{
{
while(1 == 1)
{
getJoystickSettings(joystick);
if(joy1Btn(4) == 1)
{
servo[servo2] = ServoValue[servo2]+1;
}
if(joy1Btn(2) == 1)
{
servo[servo2] = ServoValue[servo2]-1;
}
if(joy1Btn(1) == 1)
{
servo[servo1] = ServoValue[servo1]+1;
}
if(joy1Btn(3) == 1)
{
servo[servo1] = ServoValue[servo1]-1;
}
if(joystick.joy1_y1 < 5 && joystick.joy1_y1 > -5)
{
motor[motorD] = 0;
}
else
{
motor[motorD] = joystick.joy1_y1;
}
if(joystick.joy1_y2 < 5 && joystick.joy1_y2 > -5)
{
motor[motorE] = 0;
}
else
{
motor[motorE] = joystick.joy1_y2;
}
while(joy1Btn(5) == 1 && joy1Btn(6) == 0)
{
if(joystick.joy1_y1 < 5 && joystick.joy1_y1 > -5)
{
motor[motorD] = 0;
}
else
{
motor[motorD] = joystick.joy1_y1/2;
}
if(joystick.joy1_y2 < 5 && joystick.joy1_y2 > -5)
{
motor[motorE] = 0;
}
else
{
motor[motorE] = joystick.joy1_y2;
}
}
while(joy1Btn(5) == 0 && joy1Btn(6) == 1)
{
if(joystick.joy1_y1 < 5 && joystick.joy1_y1 > -5)
{
motor[motorD] = 0;
}
else
{
motor[motorD] = joystick.joy1_y1*.75;
}
if(joystick.joy1_y2 < 5 && joystick.joy1_y2 > -5)
{
motor[motorE] = 0;
}
else
{
motor[motorE] = joystick.joy1_y2*.75;
}
}
while(joy1Btn(5) == 0 && joy1Btn(6) == 0)
{
if(joystick.joy1_y1 < 5 && joystick.joy1_y1 > -5)
{
motor[motorD] = 0;
}
else
{
motor[motorD] = joystick.joy1_y1/4;
}
if(joystick.joy1_y2 < 5 && joystick.joy1_y2 > -5)
{
motor[motorE] = 0;
}
else
{
motor[motorE] = joystick.joy1_y2/4;
}
}
}
}


Tue Feb 01, 2011 8:19 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: HELP!!!!!!
To use the second controller, just use "joystick.joy2_y2" like you do joystick.joy1_y2, and "joy2Btn(5)" like you do joy1Btn(5). Now for the servos. When you write something like this:
Code:
while(true){
  if(joy1Btn(5)){ //you don't need the == 1 part because the button is true or false itself
    servo[arm]++//same thing as servo[arm] = servo[arm] + 1
  }
}


When you press the button, the computer cycles through the while loop so fast, that as soon as you hit the button, the value of the servo skyrockets. For this reason, you need the code to wait for a bit before incrementing the value. But you also can't just put a wait1Msec in there, because you don't want to interrupt other functions. There are a couple of ways to do this, but I'm going to do this with multitasking because it's simple to demonstrate and very adaptable. Multitasking is running two pieces of code at the same time(they don't really execute at the same time, but it looks like that to the user). Here is what you do:

Code:
task RunServo1(){ //declare and define the task to run
  while(true){
    if(joy1Btn(5)){
      servo[servo1]++;
    }
   
    if(joy1Btn(3)){
      servo[servo1]--;
    }
    wait1MSec(2);//Change this number to make your servo respond faster of slower

    //if Wait1Msec(1) is not fast enough, you can use servo[servo1] += x, inside the
    // if, and increase x as necessary. Make sure you keep the wait1Msec for multitaking
  }
}

task main(){
  StartTask(RunServo1);
  while(true){
    //other code
    wait1Msec(1);//for multitasking
  }
}


This is the basic layout of how to manage your servos with multitasking. There are some ways to make this code better like adding restraints to the servo value to make sure it doesn't exceed it's physical limits, but those can come after you get it working. I hope that I made things clear. Good luck.

_________________
sudo rm -rf /


Last edited by magicode on Tue Feb 08, 2011 11:35 pm, edited 1 time in total.



Tue Feb 01, 2011 10:42 pm
Profile
Rookie

Joined: Tue Feb 01, 2011 8:09 pm
Posts: 6
Post Re: HELP!!!!!!
I see. I was pretty sure all you had to do with a second controller was to use joy2Btn, but it didn't seem to work when I ran the program. It could be due to programming failure though. I will try what you said. If not, I'll ask again.
Thanks!


Tue Feb 01, 2011 11:20 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: HELP!!!!!!
A silly question, but I just want to make sure. Did you enable dual joysticks on your joystick panel?


Wed Feb 02, 2011 12:56 am
Profile
Rookie

Joined: Tue Feb 01, 2011 8:09 pm
Posts: 6
Post Re: HELP!!!!!!
To be honest, I have no idea. This is our first time with the FTC, so we have little idea of what we're doing. The controller will work fine if we use just one, but our advisor told us we needed to use 2 controllers. We're not sure how. So, tell me about this enable dual thing and mabye that's our problem.


Wed Feb 02, 2011 6:09 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: HELP!!!!!!
I don't have RobotC in front of me, so I will go by memory. In your RobotC IDE, click the Robot menu on top "Robot->NXT brick->Joystick Game". Then the joystick dialog will come up. Then you will see a check-box about Dual joystick. Make sure it is checked if you want to use two joysticks.


Wed Feb 02, 2011 6:17 pm
Profile
Rookie

Joined: Tue Feb 01, 2011 8:09 pm
Posts: 6
Post Re: HELP!!!!!!
Yep. Got it.

Okay. So, we now have the programming the way we want it.
One final question:
Our required templates are seperate, one for Autonomous, one for TeleOp. Since we obviously cannout go out onto the field and change our programs, we need a way to either switch, or add the wait for TeleOp into the Autonomous. Or do whatever we need to do. Any advice?

EDIT:Nevermind. I got it. It's working now.


Wed Feb 02, 2011 7:10 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 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.