Preseason Lesson1
From 1511Wookiee
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 we will use is connected to the Jaguar, 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 control.
The class/object type is: frc::Jaguar
We 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, we can see it based on frc::PWMSpeedController.
frc::PWMSpeedController is based on frc::SpeedController. This is important because
frc::SpeedController contains the method 'Set()', which is what we will use to
set the motor's speed. Documentation on frc::SpeedController can be found here: SpeedController
If we look at the definition of frc::SpeedController::Set, we 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. We want this to be when the robot is in tele-op mode.
This is the Robot::OperatorControl() method.
The line needs to go within the 'while' loop, and before the 'frc:Wait(0.0005)' line.
We called the varible 'm_motor', so to call its Set method, we need:
m_motor.Set(0.25);
We 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
The goal is to turn the motor at 1/4 speed, when the robot is enabled.
The motor we will use is connected to the Jaguar, 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 control.
The class/object type is: frc::Jaguar
We 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, we can see it based on frc::PWMSpeedController.
frc::PWMSpeedController is based on frc::SpeedController. This is important because
frc::SpeedController contains the method 'Set()', which is what we will use to
set the motor's speed. Documentation on frc::SpeedController can be found here: SpeedController
If we look at the definition of frc::SpeedController::Set, we 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. We want this to be when the robot is in tele-op mode.
This is the Robot::OperatorControl() method.
The line needs to go within the 'while' loop, and before the 'frc:Wait(0.0005)' line.
We called the varible 'm_motor', so to call its Set method, we need:
m_motor.Set(0.25);
We 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