|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Trouble With Variables
I should start off by saying I started this season with no experience in programming and thus learned all I know form the FRC website so please try to answer in easy to understand terms if you can. Anyway, I am trying to make a varying shooter for shooting balls and I use the variable x and when I hit the button it doesn't work. I have tried using a basic number value and it does so it has to be an issue with the variable. Here is the code:
#include <WPILib.h> /** * This is a demo program showing the use of the RobotDrive class. * The SampleRobot class is the base of a robot application that will automatically call your * Autonomous and OperatorControl methods at the right time as controlled by the switches on * the driver station or the field controls. * * WARNING: While it may look like a good choice to use for your code if you're inexperienced, * don't. Unless you know what you are doing, complex code will be much more difficult under * this system. Use IterativeRobot or Command-Based instead if you're new. */ class Robot: public frc::SampleRobot { frc::RobotDrive myRobot { 0, 1 }; // robot drive system frc::Joystick stick { 0 }; // only joystick public: Robot() { myRobot.SetExpiration(0.1); } void OperatorControl() { int x = .50; Talon *exampleTalon = new Talon(4); int buttonValue0 = stick.GetRawButton(1); int buttonValue1 = stick.GetRawButton(2); int buttonValue2 = stick.GetRawButton(3); while (IsOperatorControl() && IsEnabled()) { buttonValue0 = stick.GetRawButton(1); buttonValue1 = stick.GetRawButton(2); buttonValue2 = stick.GetRawButton(3); myRobot.ArcadeDrive(stick); // drive with arcade style (use right stick) frc::Wait(0.005); // wait for a motor update time if (x <= 1.0 and buttonValue0 == 1) { x = x + 0.005; //frc::Wait(0.005); } if (x >= 0.0 and buttonValue1 == 1) { x = x - 0.005; //frc::Wait(0.005); } if(buttonValue2 == 1) { exampleTalon->Set(x); } } } }; START_ROBOT_CLASS(Robot) Any help would be greatly appreciated. |
|
#2
|
||||
|
||||
|
Re: Trouble With Variables
If you're new to programming, you should really use RobotBuilder. It'll do all the hard work for you.
Here's the documentation |
|
#3
|
|||
|
|||
|
Re: Trouble With Variables
I tried Robot Builder but it seemed more confusing than the normal one. I also said it weird in my post above; I meant to say that I have some programming experience just never for FRC or this C++.
|
|
#4
|
|||
|
|||
|
Re: Trouble With Variables
You are attempting to assign floating point values to an integer.
|
|
#5
|
||||
|
||||
|
Re: Trouble With Variables
Time for a repost:
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|