Go to Post I guess it all just goes back to the fact that you need to finish your robot before it goes in the crate. - sanddrag [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 30-01-2010, 01:16
lmnotran lmnotran is offline
Registered User
AKA: Mason Tran
FRC #2169 (KING TeC)
Team Role: Programmer
 
Join Date: Nov 2009
Rookie Year: 2008
Location: Savage, MN
Posts: 6
lmnotran is an unknown quantity at this point
Java in RobotC for FTC TeleOp

I need help with programming. I found that you can use certain Java commands in RobotC. So I thought that I could use the Switch command which worked for some things but I have no idea how to make it work for the buttons in the TeleOp phrase.

The syntax for the Switch command is

Code:
    switch (variable)
    {
       case condition:
         action
         break;
       case condition2:
         action
         break;
       default:
         action
       break;
    }
or Just watch this YouTube video for more detail on the syntax.

http://www.youtube.com/watch?v=RVRPmeccFT0

This is my proof of concept code for Java in RobotC. It is supposed to display what button is being pressed on the NXT screen. Since this was only a proof of concept, only wrote code for Buttons 1-4 on Game controller #1(Logitech Dual action). The purpose of using the Switch command was to shorten up the code and make it less massive instead of using an IF and ELSE command for every button that will be used.

Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTMotor,  HTServo)
#pragma config(Motor,  mtr_S1_C1_1,     Intake,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     Lift,          tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C2_1,     DriveL,        tmotorNormal, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C2_2,     ShooterR,      tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C3_1,     DriveR,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C3_2,     ShooterL,      tmotorNormal, openLoop)
#pragma config(Servo,  srvo_S1_C4_1,    WingL,                tServoNormal)
#pragma config(Servo,  srvo_S1_C4_2,    WingR,                tServoNormal)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

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

void initializeRobot()
{
  servo[WingL] = 127;  // Reset Left wing position
  servo[WingR] = 127;  // Reset Right wing position
  return;
}

task main()
{
  initializeRobot();

  waitForStart();   // wait for start of tele-op phase
  
  int buttons = joystick.joy1_Buttons; // shortens the joystick.joy1_Buttons variable
  
  while(1)
  {
    getJoystickSettings(joystick); //Updates controls
    switch (buttons)
    {
      case 1:  // checks if button 1 on Joy 1 is being pressed down
        nxtDisplayCenteredTextLine(2, "Button : %d", 1);  // Display "Button: 1"
        break;
      case 2:  // checks if button 2 on Joy 1 is being pressed down
        nxtDisplayCenteredTextLine(2, "Button : %d", 2);  // Display "Button: 2"
        break;
      case 3:  // checks if button 3 on Joy 1 is being pressed down
        nxtDisplayCenteredTextLine(2, "Button : %d", 3);  // Display "Button: 3"
        break;
      case 4:  // checks if button 4 on Joy 1 is being pressed down
        nxtDisplayCenteredTextLine(2, "Button : %d", 4);  // Display "Button: 4"
        break;
      default: // if nothing is being pressed
        nxtDisplayCenteredTextLine(2, "Button : %d",  );  // Display "Button:  "
      break;
    }
  }
}
Thanks in advanced,

Mason Tran
FTC Team 3385
Lead Programmer
Reply With Quote
  #2   Spotlight this post!  
Unread 30-01-2010, 03:11
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: Java in RobotC for FTC TeleOp

The switch statement is and has always has been a C syntax... Java followed C and has a lot of C syntax incorporated in it. RobotC is just an IDE and user library. It also uses a small executive in the processor.
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
Reply With Quote
  #3   Spotlight this post!  
Unread 30-01-2010, 11:21
lmnotran lmnotran is offline
Registered User
AKA: Mason Tran
FRC #2169 (KING TeC)
Team Role: Programmer
 
Join Date: Nov 2009
Rookie Year: 2008
Location: Savage, MN
Posts: 6
lmnotran is an unknown quantity at this point
Re: Java in RobotC for FTC TeleOp

Quote:
Originally Posted by Mike Betts View Post
The switch statement is and has always has been a C syntax... Java followed C and has a lot of C syntax incorporated in it. RobotC is just an IDE and user library. It also uses a small executive in the processor.
Thanks for clarifying. But, that wasn't what I was needed help on. I wanted to know if it was possible for me to use the switch statement instead of using a bunch of IF statements for programming the buttons on the game controller for the TeleOP period.
Reply With Quote
  #4   Spotlight this post!  
Unread 30-01-2010, 19:03
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: Java in RobotC for FTC TeleOp

Quote:
Originally Posted by lmnotran View Post
Thanks for clarifying. But, that wasn't what I was needed help on. I wanted to know if it was possible for me to use the switch statement instead of using a bunch of IF statements for programming the buttons on the game controller for the TeleOP period.
Possible? Yes.

Probable? No... What variable are you gonna switch on?
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[FTC]: Java in RobotC for TeleOp lmnotran FIRST Tech Challenge 2 01-02-2010 00:14
[FTC]: Buttons RobotC JohnFogarty FIRST Tech Challenge 2 25-11-2009 19:13
[FTC]: Programming Clarification [RobotC] basicxman FIRST Tech Challenge 3 11-02-2009 20:21
[FTC]: [FTC]: RobotC Template Problem (causing an FMS issue) and Potential Servo Prob PackersFan FIRST Tech Challenge 11 26-01-2009 21:25
[FTC]: RobotC Template gdo FIRST Tech Challenge 14 10-11-2008 06:26


All times are GMT -5. The time now is 11:15.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi