View Single Post
  #1   Spotlight this post!  
Unread 25-10-2011, 11:11
austin1743 austin1743 is offline
Head Programmer - Java
FRC #1743
Team Role: Programmer
 
Join Date: Feb 2011
Rookie Year: 2009
Location: Pennsylvania
Posts: 56
austin1743 is an unknown quantity at this point
help with mecanum drive code

Hello, I am doing some off-season coding practice but I keep getting an error that i have been stumped on, Can someone help me out? just some tips or a way to go about it.

So far i have:


// things below this need to be imported first
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Dashboard;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.RobotDrive;
import com.sun.squawk.util.MathUtils;

public class RobotTemplate extends IterativeRobot {
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
RobotDrive m_robotDrive;// robot will use PWM 1-4 for drive motors

//declears speed controllers
Victor leftFrontspeed = new Victor(4, 1);
Victor rightFrontspeed = new Victor(4, 2);
Victor leftBackspeed = new Victor(4,3);
Victor rightBackspeed = new Victor(4,4);
DriverStation driverStation; // driver station object
Dashboard dashboard;

// Declare variables for the two joysticks being used
Joystick js1; // joystick 1 (arcade stick or right tank stick)


public class RobotTemplate extends IterativeRobot {
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
RobotDrive m_robotDrive;// robot will use PWM 1-4 for drive motors
public void teleopPeriodic() {
// leftspeed.set(js1.getY());
// rightspeed.set(js1.getY());

//is called when teloporated mode is enabled
double lf;//is what will be set to the left wheel speed
double rf;//is what will be set to the right wheel speed
double lb; // is what will be set to the left back wheel speed
double rb; // is what will be set to the left back wheel speed
double y = js1.getY(); //gets the value of the 1'st joystick's y axis
double x = js1.getX();//gets the value of the 1'st joystick's x axis
//y = y * Math.abs(y);//makes the y value quadratic
//x = x * Math.abs(x);//makes the x value quadratic
x=-x;
//begins meckanum code which I do not understand but it works
double magnitude =Math.sqrt(js1.getY()*js1.getY()+js1.getX()*js1.ge tX());
magnitude = magnitude*Math.sqrt(2);
double rotation = js1.getTwist();
double direction=MathUtils.atan2(x, y);
double dirInRad = (direction+45);
double sinD=Math.sin(dirInRad);
double cosD=Math.cos(dirInRad)*Math.sqrt(2);
lf=-sinD*magnitude+rotation;
rf=-cosD*magnitude-rotation;
lb=-cosD*magnitude+rotation;
rb=-sinD*magnitude-rotation;
//ends mecanum code

//lf=y;
//lb=y;
//rb=y;
//rf=y;

//runs function limit to ensure the speed of the motors is in exceptable range
lf =limit(lf,1,-1);
lb =limit(lb,1,-1);
rf =limit(rf,1,-1);
rb =limit(rb,1,-1);

//sets the motors speed
leftFrontspeed.set(lf);
leftBackspeed.set(lb);
rightFrontspeed.set(-rf);
rightBackspeed.set(-rb);

System.out.println("js1.y:"+js1.getY()+"\t js1.x:"+js1.getX()+"\t lf:"+lf+"\t rf:"+rf+"\t lb:"+lb+"\t rb:"+rb);

}

}

I get the errors saying that the following lines of code are "Cannot find symbol". I do what netbeans wants me to do and it makes a class for it but then i get a lot more errors.

If someone has just a standard drive code i can look at please refer me to that link.

thanks a lot.

Last edited by austin1743 : 25-10-2011 at 21:13. Reason: edited code to bring up to recomendations
Reply With Quote