I think I finally got my code to work but now I get an error on the dashboard that sais that motor timeout and that the motor was not refreshed enough.
I am using command based, and following a tutorial, I did not write any refreshing code so that might be it, how do I do it??
Robot.cpp
#include <Commands/Command.h>
#include <Commands/Scheduler.h>
#include <LiveWindow/LiveWindow.h>
#include <SmartDashboard/SendableChooser.h>
#include <SmartDashboard/SmartDashboard.h>
#include <TimedRobot.h>
#include <RobotDrive.h>
#include “Commands/ExampleCommand.h”
#include “Commands/MyAutoCommand.h”
#include <DriveWithJoystick.h>
class Robot : public frc::TimedRobot {
public:
void RobotInit() override {
m_chooser.AddDefault(“Default Auto”, &m_defaultAuto);
m_chooser.AddObject(“My Auto”, &m_myAuto);
frc::SmartDashboard::PutData(“Auto Modes”, &m_chooser);
}
/**
* This function is called once each time the robot enters Disabled
* mode.
* You can use it to reset any subsystem information you want to clear
* when
* the robot is disabled.
*/
void DisabledInit() override {}
void DisabledPeriodic() override {
frc::Scheduler::GetInstance()->Run();
}
/**
* This autonomous (along with the chooser code above) shows how to
* select
* between different autonomous modes using the dashboard. The sendable
* chooser code works with the Java SmartDashboard. If you prefer the
* LabVIEW Dashboard, remove all of the chooser code and uncomment the
* GetString code to get the auto name from the text box below the Gyro.
*
* You can add additional auto modes by adding additional commands to
* the
* chooser code above (like the commented example) or additional
* comparisons
* to the if-else structure below with additional strings & commands.
*/
void AutonomousInit() override {
std::string autoSelected = frc::SmartDashboard::GetString(
"Auto Selector", "Default");
if (autoSelected == "My Auto") {
m_autonomousCommand = &m_myAuto;
} else {
m_autonomousCommand = &m_defaultAuto;
}
m_autonomousCommand = m_chooser.GetSelected();
if (m_autonomousCommand != nullptr) {
m_autonomousCommand->Start();
}
}
void AutonomousPeriodic() override {
frc::Scheduler::GetInstance()->Run();
}
void TeleopInit() override {
// This makes sure that the autonomous stops running when
// teleop starts running. If you want the autonomous to
// continue until interrupted by another command, remove
// this line or comment it out.
if (m_autonomousCommand != nullptr) {
m_autonomousCommand->Cancel();
m_autonomousCommand = nullptr;
}
DriveWithJoystick(Joystick(1));
}
void TeleopPeriodic() override { frc::Scheduler::GetInstance()->Run(); }
void TestPeriodic() override {}
private:
// Have it null by default so that if testing teleop it
// doesn’t have undefined behavior and potentially crash.
frc::Command* m_autonomousCommand = nullptr;
ExampleCommand m_defaultAuto;
MyAutoCommand m_myAuto;
frc::SendableChooser<frc::Command*> m_chooser;
};
START_ROBOT_CLASS(Robot)
Chassis.h
#ifndef Chassis_H
#define Chassis_H
#include <Wpilib.h>
#include <Commands/Subsystem.h>
class Chassis : public Subsystem {
private:
RobotDrive* drive;
public:
Chassis();
void InitDefaultCommand();
void ArcadeDrive(Joystick* stick);
};
#endif // Chassis_H
chassis.cpp
#include “Chassis.h”
#include “…/RobotMap.h”
#include <Wpilib.h>
Chassis::Chassis() : Subsystem(“ExampleSubsystem”)
{
drive = new RobotDrive(1, 2);
}
void Chassis::InitDefaultCommand() {
// Set the default command for a subsystem here.
//SetDefaultCommand(new DriveWithJoystick());
}
void Chassis::ArcadeDrive(Joystick* stick)
{
drive->ArcadeDrive(stick);
}
DriveWithJoystick.h
#ifndef DriveWithJoystick_H
#define DriveWithJoystick_H
#include “…/CommandBase.h”
class DriveWithJoystick : public CommandBase {
public:
DriveWithJoystick();
void Initialize();
void Execute();
bool IsFinished();
void End();
void Interrupted();
};
#endif // DriveWithJoystick_H
DriveWithJoystick.cpp
#include “DriveWithJoystick.h”
#include <Wpilib.h>
DriveWithJoystick::DriveWithJoystick() {
// Use Requirehere to declare subsystem dependencies
}
// Called just before this Command runs the first time
void DriveWithJoystick::Initialize() {
}
// Called repeatedly when this Command is scheduled to run
void DriveWithJoystick::Execute() {
chassis->ArcadeDrive(oi->GetJoystick());
}
// Make this return true when this Command no longer needs to run execute()
bool DriveWithJoystick::IsFinished() {
return false;
}
// Called once after isFinished returns true
void DriveWithJoystick::End() {
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
void DriveWithJoystick::Interrupted() {
}
Should I include anything else? I really don’t know what to do…
Thanks