Go to Post wood is the original carbon fibre! - dtengineering [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Spotlight this post!  
Unread 01-04-2011, 23:38
Fletch1373's Avatar
Fletch1373 Fletch1373 is offline
Registered User
AKA: Fletch
FRC #3181 (Panthers)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2004
Location: Rochester, NY
Posts: 251
Fletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud of
Re: Line Following

What is the reasoning for inverting the front-right and back-left motors? Was youxinche95 correct that you're using mecanum wheels? If so, there are drive functions available in the WPILib Library to handle that.


Going on the assumption that you are using mecanum, I would recommend reading about these functions in the RobotDrive class: mecanumDrive_Polar and mecanumDrive_Cartesian. With either of these, you specify a direction vector(in either X- and Y-speed values, or as separate magnitude and direction).

You can simply strafe to the right or left, or rotate independent of direction depending on the values returned from the line sensors.

As for testing for all possible cases, you would have to write a lot of code... or would you?

While working with my team, 3555 and also a rookie this year, the programmers and I decided to figure out all possible cases and when they could happen. Knowing that we have 3 sensors that return boolean true/false values, we can use simple algebra to calculate the number of possible cases as 2^3 or 8. We also decided that a switch-case statement would work best to allow us to group similar cases together(such as left only and left/middle being tripped both telling the robot it has to move left). In order to use the switch-case, we need all the sensor values to be packed together into a single variable.

Now converting from boolean to integer is kinda weird in Java. (int)l1.get() doesn't work... from what I've found, the simplest way to do it would be with a ternary operator(don't know what this is? then run away while you still can....). For anyone that doesn't know, a ternary operator takes a condition statement and does something based on it's result, all on a single line(basically it's an if-else, but all on one line... and makes sight-reading of code very difficult sometimes[usually])... So to build our packed variable, we took 3 ternary operators, bit-shifted them to the appropriate place, then bitwise-OR'd them together.
Code:
int lineL = ((L1.get())?1:0);
int lineM = ((L2.get())?1:0);
int lineR = ((L3.get())?1:0);
int line = lineL<<2 | lineM<<1 | lineR;
After this, we can use the line variable in our switch statement. Our cases are the base-10 integer representation of the 3bit packed variable(0,1,2,3,4,5,6,7). Doing some simple binary conversions(and leaving comments with them already done), allows you to organize your cases in a logical way(if you plan to group them at least. Otherwise order doesn't matter.). Just remember not to include a break; for the cases you plan to group. When they are used the program can run down the list executing code for the similar case instead(so you don't have to write the code multiple times).
Code:
switch(line)
{
case 4:          // 1_0_0
   // notice no break
case 6:          // 1_1_0
   // do some code
   break;
<insert more cases>
}
__________________
Student:
<04: FRC0213> <05-08: FRC1373>
Mentor:
<09-10: FRC0809> <11-12: FRC3555> <12-14: FRC0073> <15-??: FRC3181>
Volunteer:
<FTAA> <CSA> <Defense Coordinator> <Scorekeeper> <Robot Inspector> <Official Scorer>
2016 Tour:
CTWAT [DefCoord] > Pittsburgh[Mentor/DefCoord] > TVR[FTAA] > FLR[CSA] > NE DCMP[CSA] > CMP[CSA]
Reply With Quote
 


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


All times are GMT -5. The time now is 10:44.

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