|
| 1 | +/*----------------------------------------------------------------------------*/ |
| 2 | +/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */ |
| 3 | +/* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 4 | +/* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | +/* the project. */ |
| 6 | +/*----------------------------------------------------------------------------*/ |
| 7 | +#define _USE_MATH_DEFINES |
| 8 | + |
| 9 | +#include <cmath> |
| 10 | +#include <string> |
| 11 | +#include <iostream> |
| 12 | +#include <thread> |
| 13 | +#include <vector> |
| 14 | +#include <frc/AnalogInput.h> |
| 15 | +#include <frc/Compressor.h> |
| 16 | +#include <frc/DoubleSolenoid.h> |
| 17 | +#include <frc/Drive/DifferentialDrive.h> |
| 18 | +#include <frc/TimedRobot.h> |
| 19 | +#include <frc/Timer.h> |
| 20 | +#include <frc/Joystick.h> |
| 21 | +#include <frc/PowerDistributionPanel.h> |
| 22 | + |
| 23 | +#include <frc/smartdashboard/SmartDashboard.h> |
| 24 | +#include <frc/SpeedControllerGroup.h> |
| 25 | +#include <opencv2/core/core.hpp> |
| 26 | +#include <opencv2/core/types.hpp> |
| 27 | +#include <opencv2/imgproc/imgproc.hpp> |
| 28 | +#include <opencv2/opencv.hpp> |
| 29 | +#include <wpi/raw_ostream.h> |
| 30 | +#include <wpi/raw_ostream.h> |
| 31 | + |
| 32 | +#include "ctre/phoenix/motorcontrol/FollowerType.h" |
| 33 | +#include "frc/WPILib.h" |
| 34 | +#include "ctre/Phoenix.h" |
| 35 | +#include <frc/SpeedController.h> |
| 36 | + |
| 37 | +#include <frc/Encoder.h> |
| 38 | + |
| 39 | +using namespace std; |
| 40 | +using namespace frc; |
| 41 | +using namespace cv; |
| 42 | +using namespace ctre; |
| 43 | +using namespace can; |
| 44 | +using namespace lowlevel; |
| 45 | + |
| 46 | + |
| 47 | +/** |
| 48 | + * This sample program shows how to control a motor using a joystick. In the |
| 49 | + * operator control part of the program, the joystick is read and the value is |
| 50 | + * written to the motor. |
| 51 | + * |
| 52 | + * Joystick analog values range from -1 to 1 and speed controller inputs as |
| 53 | + * range from -1 to 1 making it easy to work together. |
| 54 | + */ |
| 55 | +class Robot : public frc::TimedRobot { |
| 56 | + public: |
| 57 | + void RobotInit() { |
| 58 | + forklift.ConfigSelectedFeedbackSensor(FeedbackDevice::QuadEncoder, 0); |
| 59 | + forklift.Config_kF(0, 0.0);//Need to set PID and maybe F |
| 60 | + forklift.Config_kP(0, 0.1); |
| 61 | + forklift.Config_kI(0, 0.0); |
| 62 | + forklift.Config_kD(0, 0.0); |
| 63 | + forklift.SetSensorPhase(false);//VERIFY |
| 64 | + |
| 65 | + forklift.SetSelectedSensorPosition(forklift.GetSelectedSensorPosition(0), 0);//I think this captures that starting point and whill base all changes to postion off of this point |
| 66 | + } |
| 67 | + |
| 68 | + void TeleopInit() { |
| 69 | + |
| 70 | + } |
| 71 | + void TeleopPeriodic() override { |
| 72 | + if (joystick.GetRawButton() == 1) { |
| 73 | + forklift.Set(ControlMode::Position, heightOne * 4096);//4096 is the number of ticks counted in a full rotaion of the encoder, |
| 74 | + } else if (joystick.GetRawButton() == 1) { |
| 75 | + forklift.Set(ControlMode::Position, heightTwo * 4096); |
| 76 | + } else if (joystick.GetRawButton() == 1) { |
| 77 | + forklift.Set(ControlMode::Position, heightThree * 4096); |
| 78 | + } else { |
| 79 | + forklift.Set(ControlMode::Position,); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + private: |
| 84 | + Faults faults = Faults(); |
| 85 | + Joystick joystick{0}; |
| 86 | + WPI_VictorSPX forklift{5};//NEED TO SET REAL CAN ID |
| 87 | + |
| 88 | + int heightOne = 1; |
| 89 | + int heightTwo = 2; |
| 90 | + int heightThree = 3; |
| 91 | +}; |
| 92 | + |
| 93 | +#ifndef RUNNING_FRC_TESTS |
| 94 | +int main() { return frc::StartRobot<Robot>(); } |
| 95 | +#endif |
0 commit comments