ROBOTC.net forums
http://robotc.net/forums/

Can Switch..Case statements b used 2 capture ranges of value
http://robotc.net/forums/viewtopic.php?f=1&t=89
Page 2 of 2

Author:  sargunster100 [ Fri Mar 21, 2008 10:15 pm ]
Post subject: 

Dick Swan wrote:
Quote:
sargunster100 wrote:
Could you please tell me what is wrong?
Code:
switch(nMotorEncoder[motorB])

You've done nothing wrong. I tried this with version 1.17 and could not find any compiler error. I might have fixed something previously that caused an error but I cannot recall.


:lol: thanks!!!!!

:idea: :lol: :lol: :lol: :lol: :lol: :lol:

Author:  sargunster100 [ Fri Mar 21, 2008 10:18 pm ]
Post subject: 

elemes wrote:
sargunster100 wrote:
Could you please tell me what is wrong?
Code:
 switch(nMotorEncoder[motorB])


1. Some cases RobotC is a little bit more restrictive, compared to standard C. For such cases I suggest using a more simple structure e.g. introducing a new temporary variable.

2. switch statement allows you branching between discrete values. resoution of motor encoder is too fine for such purpose -- the encoder value steps 360 during one rotation of the motor axle and can be anywhere in the range of -32768 .. +32767. You might want to try an "if-else" ladder:
Code:
mb = nMotorEncoder[motorB];
if( mb < your absolute lower limit ) {
  your action below reaching the lower limit;
  }
else if( mb < closer lower limit ) {
  your action when you are close to your target range;
  }
else if( mb > your absolute upper limit ) {
  your action far over the upper limit;
  }
else if( mb > closer upper limit ) {
  your action when you are slightly over the upper limit;
  }
else {
  your action when motor is within the accepted range;
  keep in mind the motor's momentum, it will turn a bit;
  even if you immediately stop it;
  }
In such a structure you can slow down the motor when you are close to the target and thus avoid "overshoot." If it is the intended operation of course.




:lol: thanks!!!!!

:idea: :lol: :lol: :lol: :lol: :lol: :lol:

ps: I was using the motor as a joystick, not as a "motor"

Page 2 of 2 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/