Datasheet

DMC60CSoftware Reference Manual
Page 13 of 16
6.1.1 C++ (Robot.cpp)
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 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. */
/*----------------------------------------------------------------------------*/
#include "Robot.h"
#include <iostream>
#include <frc/smartdashboard/SmartDashboard.h>
#include <digilent/dmc60/WPI_DMC60C.h>
#include <frc/Joystick.h>
//DMC60C with device number 5.
DMC60::WPI_DMC60C * _dmc = new DMC60::WPI_DMC60C(5);
//Joystick on USB port 0.
frc::Joystick * _joy = new frc::Joystick(0);
void Robot::RobotInit() {
//Change these depending on motor behavior.
_dmc->SetInverted(false);
_dmc->invertEncoder(false);
}
void Robot::TeleopInit() {
_dmc->zeroEncoderPosition();
}
void Robot::TeleopPeriodic() {
bool A = _joy->GetRawButton(1);
double stick = -1*_joy->GetY();
//If A button is held
if(A){
//Drive -100 to 100 percent duty cycle.
_dmc->drivePosition(stick*100);
//Report position on Smart Dashboard.
frc::SmartDashboard::PutNumber("Position", _dmc->getEncoderPositionCount());
}
else{
_dmc->Disable();
}
}
void Robot::TestPeriodic() {}
void Robot::RobotPeriodic() {}
void Robot::AutonomousInit() {}
void Robot::AutonomousPeriodic() {}
#ifndef RUNNING_FRC_TESTS
int main() { return frc::StartRobot<Robot>(); }
#endif