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"><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"><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:


Line 14: Line 14:


<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.
<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.
&nbsp;


<u><span style="font-size: large;">Test</span></u>
<u><span style="font-size: large;">Test</span></u>


#enable the Robot, in tele-op mode and watch the motor turn  
#enable the Robot, in tele-op mode and watch the motor turn  
</div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div>
</div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div>

Revision as of 10:25, 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()) {
   m_motor.Set(0.25); // spin motor forward 1/4 speed
   frc::Wait(0.005);
}

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



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.

 

Test

  1. enable the Robot, in tele-op mode and watch the motor turn