View Single Post
  #4   Spotlight this post!  
Unread 25-06-2013, 12:32
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 429
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: Robot not taking input

Re previous comments, I don't see where 'c' is being used to control a loop. So I don't think that's the cause of the robot "doing nothing".
In auto there isn't a loop (which is a problem) except for in state 4, and it has already been identified that these loops will never get executed. Not having a loop wrapping the case statements is a problem since you're never going to go through more than one case in the case statement. the autonomous() method is only called once (upon entering the mode) in the [url="http://team2168.org/javadoc/edu/wpi/first/wpilibj/SimpleRobot.html"]SimpleRobot[url] class.
You're right that 'c' is never modified though, so if you were to get to state 4 in auto, you would never be able to leave it.

I would suggest tryting to re-organize your code a bit:
In autonomous and operator control methods, you should have a while loop wrapping the majority of the code.
The while loop should terminate when you're not in the respective mode (isAutonomous() or isOperatorControl()) and the robot isn't disabled (isDisabled()).

Your case staments are set up to drive a state machine. This way of organizing your code is fine in practice. But as others noted, the code isn't outputting commands to the motors. I would suggest reorganizing your case statements such that they follow the following general outline.
Code:
while( you're in the mode and not disabled) {
  switch(state) {
    case X:
      //logic specific to the state (like checking joystick buttons)
      //set the speeds for your motors, note you may want to set the speeds
      //  for ALL motors in each state, or you risk commanding a motor
      //  to a stale value (set by some previous state).
      //Modify your state variable
      //Set a variable (e.g. double dealyTime) for how long to delay
      //  If you don't need to delay, set to zero.
    break;

    case ...:
      //you should have something similar for the remaining cases.
      //each case should
    break;
   
    default:
      //you should ALWAYS define a default case, if state ever got
      //  set to something you didn't have a case for the world will
      //  end. Note you do this in the auto code (case 4, sets state
      //  to 0, but there is not case for state=0!).
      //Since getting here is probably abnormal, you should set safe
      //  default values and maybe change into a safe starting state.
  }

  //outside the switch but inside the while
  // Output to your motors and call the delay
  runMotor();
  Timer.delay(delayTime);
}
Also note, that the way the state machine is set up right now
Ideally you wouldn't have any significant delays (greater than 50ms). It is better to have your states log the time they started, and not change into the next state until the current time exceeds the logged time plus the time you wanted to wait for. This allows the while loop to continue to run (many many times while you are stuck in a sparticular state). If your case statements are set up right this will allow you to continue to respond to operator input while in any particular state.
If you don't set the states up this way then your robot will be unresponsive to joystick commands for periods of time (however long you are delaying for). For example, once you have started to shoot, if someone bumpped into your robot, there is no way for you to correct your alignment until after your shot sequence has completed.


I would say continue to try to implement things the way you are until you get them running. It will be an invaluable learning experience.
If you have time after this to try some more things in java, I would suggest taking a look at the command based robot project. Your state machine design means your already thinking along the right lines to come up with procedures or sequences of actions which your robot needs to perform. The command based robot project gives you a great foundation to build complex tasks upon. And its structure will help you organize your thoughts into code. My team has been using it sucessfully for the past two years.
There's a lot to digest, but it's pretty straight forward. And there is a tool called robot builder which can help generate code for you so that you may get your feet wet.
__________________
http://team2168.org
Reply With Quote