View unanswered posts | View active topics It is currently Wed Aug 20, 2014 11:19 am






Reply to topic  [ 4 posts ] 
Final Drive-Code Questions 
Author Message
Rookie

Joined: Sun Jan 23, 2011 11:24 am
Posts: 5
Post Final Drive-Code Questions
I believe I have my final code for teleOp before going to my FTC competition this Saturday. I just had some questions and was wondering if anyone could answer them for me regarding this following code:

1.) For some reason, when i toggle back on my joystick, the robot goes forward. I do not know why this occurs. It happens for both sides (y1 & y2)

2.) The robot will not come to a complete stop when I let go of the joystick. I thought I put in the right code but apparently not.

If anyone can answer these questions I would be greatly appreciative. Thanks!



#pragma config(Hubs, S1, HTMotor, HTMotor, none, none)
#pragma config(Motor, motorA, kickMotor, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorB, leftGrabber, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorC, rightGrabber, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, mtr_S1_C1_1, leftMotors, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, mtr_S1_C1_2, rightMotors, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, mtr_S1_C2_1, armMotors, tmotorNormal, PIDControl, reversed, encoder)
#pragma config(Motor, mtr_S1_C2_2, motorG, tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#include "JoystickDriver.c" //Include file to "handle" the Bluetooth messages.



void initializeRobot()
{
// Place code here to sinitialize servos to starting positions.
// Sensors are automatically configured and setup by ROBOTC. They may need a brief time to stabilize.

return;
}



task main()
{
initializeRobot();

waitForStart(); // wait for start of tele-op phase

int thresholdP = 10;
int thresholdN = -10;

while (true)
{
getJoystickSettings(joystick);
if(abs((joystick.joy1_y1)) > thresholdP);

motor[leftMotors] = (joystick.joy1_y1);

motor[leftMotors] = 0;
{
motor[leftMotors] = (joystick.joy1_y1);
}
if(abs((joystick.joy1_y2)) > thresholdP);
{
motor[rightMotors] = -(joystick.joy1_y2);

motor[armMotors] = (joystick.joy2_y2);

motor[kickMotor] = (joystick.joy2_y1);
}
}
}


Wed Jan 26, 2011 8:17 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Final Drive-Code Questions
you want the left wheels to be controlled by joystick.joy1_y1, the right wheels to be controlled by joystick.joy1_y2 when the joysticks are above the threshold right? This is how you would implement that:
Code:
while (true)
{
  getJoystickSettings(joystick);
  if(abs(joystick.joy1_y1) > thresholdP){
    motor[leftMotors] = (joystick.joy1_y1);
  }else{
    motor[leftMotors] = 0;
  }

  if(abs(joystick.joy1_y2) > thresholdP){
    motor[rightMotors] = (joystick.joy1_y2);
  }else{
    motor[rightMotors] = 0;
  }
}


When you write an if statement, you write it like this:
Code:
if(statement){
  code to execute
}

If you use a semicolon at the end, you're telling it to do nothing.

Not to confuse you, but to save space, you can also write the code like this:
Quote:
while (true)
{
getJoystickSettings(joystick);
motor[leftMotors] = abs(joystick.joy1_y1) > thresholdP ? joystick.joy1_y1 : 0;
motor[rightMotors] = abs(joystick.joy1_y2) > thresholdP ? joystick.joy1_y2 : 0;
}

_________________
sudo rm -rf /


Wed Jan 26, 2011 11:36 pm
Profile
Rookie

Joined: Sun Jan 23, 2011 11:24 am
Posts: 5
Post Re: Final Drive-Code Questions
Ok thank-you that helped a lot. This might also be a stupid question, but how do you make the buttons work on the joystick?

I know that joystick.joy1_y1 or y2 are the toggles, but how does it connect to a button?

Would it be something like (joystick.joy1_btn2)?

Thanks!


Thu Jan 27, 2011 12:37 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Final Drive-Code Questions
For all your syntax questions, there are a host of RobotC sample programs. I don't have RobotC in front of me right now, but it's something like joy1Btn(Button Number).

_________________
sudo rm -rf /


Thu Jan 27, 2011 2:18 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 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.