Thread: Line Following
View Single Post
  #7   Spotlight this post!  
Unread 02-04-2011, 12:10
pigpc1993 pigpc1993 is offline
Registered User
AKA: Colin Feeney
FRC #3716 (WARP)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2009
Location: Manhasset, NY
Posts: 41
pigpc1993 is an unknown quantity at this point
Re: Line Following

Quote:
Originally Posted by Fletch1373 View Post
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>
}
I'm sorry but I don't understand what a Mecanum drive is exactly. I'm going to research it. Anyway we found out what our problem was. youxinche95 was correct with the else statement and we also had a bad Victor. Apparently it smoked at one point or another and was only able to go at full power even after multiple calibration attempts. I don't understand why it happened like that. We tried running it again after calibration and it started smoking more so we replaced it. Thanks for the help guys.

Edit:
I looked at pictures and information about Mecanum drives and we don't have that.

Last edited by pigpc1993 : 02-04-2011 at 12:16.
Reply With Quote