We were able to get the chassis to move, but unable to code the shooter. We would appreciate some advice and help on how to code a shooter.
What language are you using? What framework (Timed robot, command based, etc)?
Edit: I see now that it’s under the Java category
We are using java
Are you using command based?
Yes we are
Perfect
Can you describe what you all need to do? Run a conveyor, turn on a shooter, deploy pneumatics?
Do you have your code on github?
A few steps you can take right now:
Subsystem
- Create a new subsystem called Shooter
- Add the shooter motor controller(s)
- Create a function to turn them on/off (I normally have a function to just set the speed)
Command
- Create a command to control the shooter
- Use command to turn on the shooter’s motor
Robot Container
- Bind joystick buttons to command
Take a look at our code.
It is not at all advanced or complicated. It is basically the bare minimum we need to run the robot (which is all we really need anyways)
You’ll see how we do the shooter and the commands
Also don’t forget to check out the docs:
https://frc-docs.readthedocs.io/en/latest/docs/software/commandbased/index.html
They’re not the best but they cover all the bases
We want to turn on a shooter with two bag motors, left and right. We want to use a button on a joystick to turn on when pressed. We do not have our code github
How are the bag motors connected to the shooter? This matters because you’re either going to run them together (same direction) or inverted from each other (opposite directions)
They are both connected by belts. The motors are connected to spark motor control into the pwm inputs. We want to make them spin in opposite directions
Can you post your code that you are using to get the drive train running? If so, we can better understand where you are at with coding, and adjust our explanation accordingly.
We are unable to send our code due to being new users
Right on.
Your subsystem code should look something similar to this:
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package frc.robot.subsystems;
import edu.wpi.first.wpilibj.Spark;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
public class Shooter_CD_Example extends SubsystemBase {
// 5 = PWM Channel #
private final Spark leftMotor = new Spark(5);
// 6 = PWM Channel #
private final Spark rightMotor = new Spark(6);
/**
* Creates a new Shooter_CD_Example.
*/
public Shooter_CD_Example() {
// Set the right motor to be inverted so the motors don't fight each other
rightMotor.setInverted(true);
}
public void setShooterSpeed(double speed) {
leftMotor.setSpeed(speed);
rightMotor.setSpeed(speed);
}
@Override
public void periodic() {
// This method will be called once per scheduler run
}
}
Thank you for the help
Next you should create a command to call that.
Try and figure how you’re going to do that. Hint: You can right click on the “commands” folder in Visual Studio Code, then click on “Create New Class/Command” (at the bottom), then type in Command. Pick the New Instant Command, it’s all you really need. You should read up on the different types of commands
From this we shouldn’t have much problems coding to shoot from a button press
Thank you for all the help
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.