Log in

View Full Version : New to FRC Programming


samrmur
10-02-2016, 20:29
Hello,

I'm very new to FRC programming and need help programming my team's robot because we don't have much time remaining. I've tried doing what I can but it doesn't work. My team has 6 Victors for the drive train and since the RobotDrive.class only support up to 4, I am unsure how to connect the other two. Also, when opening up SmartDashboard, no options for the autonomous commands display and I am unsure how to display it. My code has been uploaded to GiftHub: https://github.com/samrmur/FRCRobot/blob/master/FRC%20Robot/src/org/usfirst/frc/team3756/robot/LaurierRobot.java

Thanks in Advance,
Samer

rich2202
10-02-2016, 21:26
How are the 6 motors driving the wheels?

If any are in 2 motor gear boxes, then you can use a Pwm splitter to drive the two motor controllers. It will then look like one motor to the software.

pblankenbaker
10-02-2016, 23:18
The PWM splitter is a great way to solve this problem.

If you don't have a PWM splitter and it will take you awhile to get one, you can use a software approach by adding a new SpeedControllerArray class to your project (shown below). This class controls an array of motors as if they were one. It is a simple implementation that expects that all of the motors turn the same direction (for example, if you want to set a power of .5 on one, you will be setting them all to .5).

To use the SpeedControllerArray class in your Robot.java, you will need to create a SpeedControllerArray.java file with the code shown below in the same package as your Robot.java file and then change your RobotDrive construction from:


RobotDrive driveRobot = new RobotDrive(frontLeft, backLeft, frontRight, backRight);


To:


SpeedController[] leftSideMotors = { frontLeft, middleLeft, backLeft };
SpeedController[] rightSideMotors = { frontRight, middleRight, backRight };

SpeedController leftSide = new SpeedControllerArray(leftSideMotors);
SpeedController rightSide = new SpeedControllerArray(rightSideMotors);

RobotDrive driveRobot = new RobotDrive(leftSide, rightSide);


Here is the source for the SpeedControllerArray class. NOTE: Please review (I think it is OK, but it has not been verified it on a live robot).


package org.usfirst.frc.team3756.robot;

import edu.wpi.first.wpilibj.SpeedController;

/**
* A SpeedController implementation that wraps an array of one or more
* SpeedController objects so they look like a single SpeedController (a
* software version of a PWM splitter cable).
*/
public class SpeedControllerArray implements SpeedController {

// Array of motors to control like one
private SpeedController[] motors;

public SpeedControllerArray(SpeedController[] motors) {
if (motors.length < 1) {
throw new IllegalArgumentException("You must pass an array of at least one SpeedController");
}
this.motors = motors;
}

@Override
public void pidWrite(double output) {
set(output);
}

@Override
public double get() {
// Since all motors have same value, return value from first one
return motors[0].get();
}

@Override
public void set(double speed, byte syncGroup) {
for (SpeedController motor : motors) {
motor.set(speed, syncGroup);
}
}

@Override
public void set(double speed) {
for (SpeedController motor : motors) {
motor.set(speed);
}
}

@Override
public void setInverted(boolean isInverted) {
for (SpeedController motor : motors) {
motor.setInverted(isInverted);
}
}

@Override
public boolean getInverted() {
// Since all motors have same value, return value from first one
return motors[0].getInverted();
}

@Override
public void disable() {
for (SpeedController motor : motors) {
motor.disable();
}
}

}


Good luck, and I hope you found the PWM splitter cable as that is a simpler hardware solution to the problem.

samrmur
11-02-2016, 15:41
It worked, but today we figured out that the problem was not with the code, the wiring was messed up and the gear boxes are not working properly, thanks for the help