Preseason Lesson1

From 1511Wookiee
Revision as of 10:13, 15 December 2019 by Programming (talk | contribs)
Jump to navigationJump to search
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>
   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.