Advertisement
Guest User

Rahr

a guest
Jan 16th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. #include "WPILib.h"
  2. #include "NetworkTables/NetworkTable.h"
  3.  
  4.  
  5. class Robot: public IterativeRobot {
  6.  
  7. public:
  8. // Network Table Test
  9. std::shared_ptr<NetworkTable> table;
  10.  
  11. private:
  12. Joystick xbox;
  13.  
  14. // Solenoid Control
  15. DoubleSolenoid *sol;
  16.  
  17. CANTalon testMotor;
  18. int position;
  19.  
  20.  
  21.  
  22.  
  23.  
  24. public:
  25. Robot():
  26. xbox(0),
  27.  
  28. // sol(1,2),
  29. // solVal(DoubleSolenoid::Value::kForward),
  30.  
  31. testMotor(9),//Tilter==5
  32. position(0)
  33.  
  34. {
  35. sol = new DoubleSolenoid(1,2);
  36.  
  37. testMotor.SetFeedbackDevice(CANTalon::QuadEncoder);
  38. testMotor.SetControlMode(CANTalon::kPosition);
  39. testMotor.SetPID(0,0,0);
  40.  
  41. table = NetworkTable::GetTable("Rio_to_Client");
  42. }
  43.  
  44. private:
  45.  
  46. void RobotInit(){
  47. //No idea when this is called
  48. }
  49.  
  50. void AutonomousInit(){
  51. //Called once at the start of each Auto period
  52. }
  53.  
  54. void AutonomousPeriodic(){
  55. //Called PERIODICALLY during the Auto period
  56. }
  57.  
  58. void TeleopInit(){
  59. //Called once at the start of each operator period
  60. printf("TELEOP Initialized\n");
  61. }
  62. void DisabledInit(){
  63. printf("Disabled TELEOP\n");
  64. }
  65.  
  66. void TeleopPeriodic(){
  67. //Called PERIODICALLY during the operator period
  68.  
  69. float valX = xbox.GetRawAxis(XBox::rightX);
  70. // float valY = xbox.GetRawAxis(XBox::rightY);
  71.  
  72. // SmartDashboard::PutString("DB/String 0","Joystick: [ %4f , "+str(valY)+" ]");
  73. // printf("Joystick: [ %.4f , %.4f]\n",valX,valY);
  74. // printf("X: [ %.4f ]\tTalon: [ %.4f ]\n",valX,testMotor.GetOutputVoltage());
  75.  
  76. // abs(x) function is funky. if (abs(valX) > 0.015) -> -1 or 0 or 1 talon output
  77.  
  78.  
  79. // SmartDashboard::PutString("DB/String 0","Encoder:");
  80. // SmartDashboard::PutString(testMotor.GetEncPosition());
  81.  
  82. bool solMode = false;
  83.  
  84. if (solMode){
  85. if (xbox.GetRawButton(XBox::b)){
  86. // solVal = DoubleSolenoid::Value::kForward;
  87. sol->Set(DoubleSolenoid::Value::kForward);
  88. printf("Go Forward\n");
  89. } else if (xbox.GetRawButton(XBox::x)){
  90. // solVal = DoubleSolenoid::Value::kReverse;
  91. sol->Set(DoubleSolenoid::Value::kReverse);
  92. printf("Go Back\n");
  93. } else {
  94. // solVal = DoubleSolenoid::Value::kOff;
  95. sol->Set(DoubleSolenoid::Value::kOff);
  96. printf("Off\n");
  97. }
  98. // printf("SolVal: %d\n",solVal);
  99.  
  100.  
  101. // printf("Where it is: %d\n",testMotor.GetEncPosition());
  102. // printf("Where it wants to be: %d\n",position);
  103.  
  104. if (valX >0.15 || valX < -0.15){
  105. position += valX*10;
  106. }
  107. //Read in PID values from SD
  108. testMotor.SetP(SmartDashboard::GetNumber("DB/Slider 0",0));
  109. testMotor.SetI(SmartDashboard::GetNumber("DB/Slider 1",0));
  110. testMotor.SetD(SmartDashboard::GetNumber("DB/Slider 2",0));
  111.  
  112. testMotor.Set(position);
  113. // sol->Set(solVal);
  114. }//solMode
  115.  
  116. /*
  117. {//Test1
  118. float x = table->GetNumber("X",4);
  119. printf("X: %f\n",x);
  120.  
  121. table->PutNumber("VAL",valX);
  122. printf("Y:%f\n",table->GetNumber("VAL",-1));
  123. }
  124. */
  125.  
  126. table->PutNumber("Cheesy",254);
  127. // printf("ClientVal: %f\n",table->GetNumber("ClientVal",254));
  128. }
  129.  
  130. void TestPeriodic(){
  131. //Who knows (We don't use this)
  132. }
  133. };
  134.  
  135. START_ROBOT_CLASS(Robot)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement