Preseason Lesson1: Difference between revisions
Programming (talk | contribs) No edit summary |
Programming (talk | contribs) 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"><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 you will use is connected to 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/> | <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 you will use is connected to 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/> | ||
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 6: | Line 6: | ||
The '{2}' indicates the contructor will be called and '2' wil be passed in for the channel parameter.<br/> <br/> <br/> <br/> 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: [https://first.wpi.edu/FRC/roborio/release/docs/cpp/classfrc_1_1SpeedController.html SpeedController]<br/> <br/> 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.<br/> <br/> 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.<br/> You will call the 'Set()' method for the object/varible 'm_motor' | The '{2}' indicates the contructor will be called and '2' wil be passed in for the channel parameter.<br/> <br/> <br/> <br/> 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: [https://first.wpi.edu/FRC/roborio/release/docs/cpp/classfrc_1_1SpeedController.html SpeedController]<br/> <br/> 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.<br/> <br/> 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.<br/> You will call the 'Set()' method for the object/varible 'm_motor' | ||
</div> <div class="mw-parser-output"><pre>while (IsOperatorControl() && IsEnabled()) { | </div> <div class="mw-parser-output"><pre>while (IsOperatorControl() && IsEnabled()) { | ||
m_motor.Set(0.25); // spin motor forward 1/4 speed | |||
frc::Wait(0.005); | frc::Wait(0.005); | ||
} | } | ||
Line 14: | Line 12: | ||
You pass in '0.25' to tell it go 1/4 speed forward. | You pass in '0.25' to tell it go 1/4 speed forward. | ||
<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. | ||
</div> </div> </div> </div> </div> </div> </div> </div> </div> | </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> |
Revision as of 10:16, 15 December 2019
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.