Preseason Lesson1: Difference between revisions

From 1511Wookiee
Jump to navigationJump to search
No edit summary
No edit summary
Line 1: Line 1:
<div class="mw-parser-output"><div class="mw-parser-output"><div class="mw-parser-output"><div class="mw-parser-output"><div class="mw-parser-output"><div class="mw-parser-output"><div class="mw-parser-output"><span style="font-size: large;">'''Turn motor when robot is enabled'''</span><br/> <br/> The goal is to turn the motor at 1/4 speed, when the robot is enabled.<br/> <br/> The motor&nbsp;you will use is connected to&nbsp;a Jaguar motor controller, which is connected to channel 2.<br/> <br/> The link to the Jaguar documentation: [https://first.wpi.edu/FRC/roborio/release/docs/cpp/classfrc_1_1Jaguar.html Jaguar]<br/> &nbsp;  
<div class="mw-parser-output"><div class="mw-parser-output"><div class="mw-parser-output"><div class="mw-parser-output"><div class="mw-parser-output"><div class="mw-parser-output"><div class="mw-parser-output"><div class="mw-parser-output"><div class="mw-parser-output"><span style="font-size: large;">'''Turn motor when robot is enabled'''</span><br/> <br/> The goal is to turn the motor at 1/4 speed, when the robot is enabled.<br/> <br/> The motor&nbsp;you will use is connected to&nbsp;a Jaguar motor controller, which is connected to channel 2.<br/> <br/> The link to the Jaguar documentation: [https://first.wpi.edu/FRC/roborio/release/docs/cpp/classfrc_1_1Jaguar.html Jaguar]<br/> &nbsp;  
In Robot.h we will need an object/variable that is the Jaguar motor controller. The class/object type is: '''frc::Jaguar'''. You will name the object: '''m_motor'''. In Robot.h, in the 'private:' section add the following line:
In Robot.h we will need an object/variable that is the Jaguar motor controller. The class/object type is: '''frc::Jaguar'''. You will name the object: '''m_motor'''. In Robot.h, in the 'private:' section add the following line:
<pre>  frc::Jaguar m_motor{2};
<pre>  frc::Jaguar m_motor{2};
Line 7: Line 7:
</div> <div class="mw-parser-output"><pre>while (IsOperatorControl() && IsEnabled()) {
</div> <div class="mw-parser-output"><pre>while (IsOperatorControl() && IsEnabled()) {
   <span style="color: rgb(231, 76, 60);">m_motor.Set(0.25); // spin motor forward 1/4 speed</span>
   <span style="color: rgb(231, 76, 60);">m_motor.Set(0.25); // spin motor forward 1/4 speed</span>
<span style="color: rgb(231, 76, 60);">&nbsp;&nbsp; if (joystick trigger is pressed) { if (joystick position is greater than 0.33) { spin motor forward 1/4 speed } else if (joystick position is less than -0.33) { spin motor reverse 1/4 speed } else { stop motor } }</span>
  frc::Wait(0.005);
}
</pre>
You&nbsp;pass in '0.25' to tell it go 1/4 speed forward.
&nbsp;
You will want to first test if the trigger is pressed. If it is pressed, then you will look at the position to see if the position to determine how to turn the motor. Here is the pseudo code (i.e. not actual code, replace the English words with actual code):
<pre>while (IsOperatorControl() && IsEnabled()) {
<span style="color: rgb(231, 76, 60);">  if (joystick trigger is pressed) {
      if (joystick position is greater than 0.33) {
          spin motor forward 1/4 speed
      }
      else if (joystick position is less than -0.33) {
          spin motor reverse 1/4 speed
      }
      else {
          stop motor
      }
  }</span>
   frc::Wait(0.005);
   frc::Wait(0.005);
}
}
</pre>
</pre>


You&nbsp;pass in '0.25' to tell it go 1/4 speed forward.<br/> <br/> <br/> After you have modified Robot.h and Robot.cpp, build the project: [[Preseason_Build_Project|Preseason Build Project]]. Once project builds without errors, let instructor know you are ready to try to delpoy and test. Do not deploy until told to.
The 0.33 and -0.33 is make sure the joystick has moved away from the center. Ideally, you would get 0 when the joystick is at the center. However, joysticks do not always go back to true 0.
</div> </div> </div> </div> </div> </div> </div>
 
<br/> <br/> After you have modified Robot.h and Robot.cpp, build the project: [[Preseason_Build_Project|Preseason Build Project]]. Once project builds without errors, let instructor know you are ready to try to delpoy and test. Do not deploy until told to.
</div> </div> </div> </div> </div> </div> </div> </div> </div>

Revision as of 10:15, 15 December 2019

Turn motor when robot is enabled

The goal is to turn the motor at 1/4 speed, when the robot is enabled.

The motor you will use is connected to a Jaguar motor controller, which is connected to channel 2.

The link to the Jaguar documentation: Jaguar
 

In Robot.h we will need an object/variable that is the Jaguar motor controller. The class/object type is: frc::Jaguar. You will name the object: m_motor. In Robot.h, in the 'private:' section add the following line:

   frc::Jaguar m_motor{2};

The '{2}' indicates the contructor will be called and '2' wil be passed in for the channel parameter.



Looking at the frc::Jaguar class, you can see it based on frc::PWMSpeedController. And that frc::PWMSpeedController is based on frc::SpeedController. This is important because frc::SpeedController contains the method 'Set()', which is what you will use to set the motor's speed. Documentation on frc::SpeedController can be found here: SpeedController

If you look at the definition of frc::SpeedController::Set(), you will see that it takes a double (i.e. decimal value) from -1.0 to 1.0. Negative values spin the motor in reverse, and positive values spin it forward. So 1.0 is full forward speed.

In Robot.cpp, you will tell the motor to turn. You want this to be when the robot is in tele-op mode. When in tele-op mode, the Robot::OperatorControl() method is called. The line, you will add, needs to go within the 'while' loop, and before the 'frc:Wait(0.0005)' line.
You will call the 'Set()' method for the object/varible 'm_motor'

while (IsOperatorControl() && IsEnabled()) {
   <span style="color: rgb(231, 76, 60);">m_motor.Set(0.25); // spin motor forward 1/4 speed</span>
<span style="color: rgb(231, 76, 60);">   if (joystick trigger is pressed) { if (joystick position is greater than 0.33) { spin motor forward 1/4 speed } else if (joystick position is less than -0.33) { spin motor reverse 1/4 speed } else { stop motor } }</span>

   frc::Wait(0.005);
}

You pass in '0.25' to tell it go 1/4 speed forward.

 

You will want to first test if the trigger is pressed. If it is pressed, then you will look at the position to see if the position to determine how to turn the motor. Here is the pseudo code (i.e. not actual code, replace the English words with actual code):

while (IsOperatorControl() && IsEnabled()) {
<span style="color: rgb(231, 76, 60);">   if (joystick trigger is pressed) {
       if (joystick position is greater than 0.33) {
           spin motor forward 1/4 speed
       }
       else if (joystick position is less than -0.33) {
           spin motor reverse 1/4 speed
       }
       else {
           stop motor
       }
   }</span>
   frc::Wait(0.005);
}

The 0.33 and -0.33 is make sure the joystick has moved away from the center. Ideally, you would get 0 when the joystick is at the center. However, joysticks do not always go back to true 0.



After you have modified Robot.h and Robot.cpp, build the project: Preseason Build Project. Once project builds without errors, let instructor know you are ready to try to delpoy and test. Do not deploy until told to.