View unanswered posts | View active topics It is currently Sun Aug 31, 2014 6:33 am






Reply to topic  [ 17 posts ]  Go to page Previous  1, 2
Can Switch..Case statements b used 2 capture ranges of value 
Author Message
Rookie

Joined: Sat Jan 19, 2008 1:35 pm
Posts: 5
Post 
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:


Fri Mar 21, 2008 10:15 pm
Profile
Rookie

Joined: Sat Jan 19, 2008 1:35 pm
Posts: 5
Post 
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"


Fri Mar 21, 2008 10:18 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 17 posts ]  Go to page Previous  1, 2

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.