|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Button programin C++
so my team is using mecanum wheels this year. we would like to make it so when you hit the trigger on the left joystick it reduces the maximum speed of the motor by half. so im my code i have this
Code:
bool GetTrigger (Joystick hand = leftstick); i was trying to create an if statement to change the speed of the motors but its not working. any suggestions? |
|
#2
|
||||
|
||||
|
Re: Button programin C++
..
Last edited by krudeboy51 : 23-01-2011 at 19:46. |
|
#3
|
|||
|
|||
|
Re: Button programin C++
Wouldn't doubling the speed make it go faster unless you puss the trigger?
What I'm looking to do is while in operator control drive mecanum drive full power, but when you get close to the pegs you press the trigger and you drive at half the speed. Does that make sense? |
|
#4
|
||||
|
||||
|
Re: Button programin C++
..
Last edited by krudeboy51 : 23-01-2011 at 19:45. |
|
#5
|
|||
|
|||
|
Re: Button programin C++
Try this:
if ( !stick.GetTrigger()){ motors.Set(x); } else{ motors.Set(x/2); } This code assumes that x is the input variable that you use for speed. For driver control, this would be the value you get from your joysticks. It works by checking to see if the trigger is pressed. If not, then the speed is just as normal. If the trigger is pressed, then the speed is half of what it would normally be. Hope this is what you meant. |
|
#6
|
|||
|
|||
|
Re: Button programin C++
That's what I ment thanks
![]() |
|
#7
|
|||
|
|||
|
Re: Button programin C++
would i put that before:
bool GetTrigger.... of after it cause i just tried to build it and i got a boat load of errors |
|
#8
|
|||
|
|||
|
Re: Button programin C++
If your joystick's name in the program is "hand" then the portion of the code that needs to be the argument for the if statement is as follows: "hang.GetTrigger()".
The code segment would look like if ( !hand.GetTrigger()){ motors.Set(x); } else{ motors.Set(x/2); } You don't need a boolean variable for this code, only the value coming directly from the joystick. |
|
#9
|
|||
|
|||
|
Re: Button programin C++
it dosent like motors.set(x)
do i have to declare each motor leftmotor.set(x),rightmotor.... |
|
#10
|
|||
|
|||
|
Re: Button programin C++
I am sorry, I forgot to mention that the "motors.Set()" section was just a stand in for whatever functions you use to move. You would either replace the "motors" part with the motors that you declared earlier in your program or replace the "motors.Set()" function with whatever function you were using to drive.
For example, if you declared your motors previously as LeftMotor and RightMotor, then the code would look like: if ( !stick.GetTrigger()){ LeftMotor.Set(x); RightMotor.Set(x); } else{ LeftMotor.Set(x/2); RightMotor.Set(x/2); } Sorry about forgetting to include that little tidbit. If you have any more problems with your code, post a copy of the driver section so we can see what might be the problem. |
|
#11
|
|||
|
|||
|
Re: Button programin C++
i tried to put in left motor and other stuff
here is the code Code:
#include "WPILib.h"
#include "Vision/AxisCameraParams.h"
/**
* This is a demo program showing the use of the RobotBase class.
* The SimpleRobot 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.
*/
class RobotDemo : public SimpleRobot
{
RobotDrive myRobot; // robot drive system
Joystick leftstick; // only joystick
Joystick rightstick; // only joystick
HSLImage image;
public:
RobotDemo(void):
myRobot(1, 2, 3, 4), // these must be initialized in the same order
leftstick(1), // as they are declared above.
rightstick(2) // as they are declared above.
{
myRobot.SetExpiration(0.1);
}
/**
* Drive left & right motors for 2 seconds then stop
*/
void Autonomous(void)
{
myRobot.SetSafetyEnabled(false);
myRobot.Drive(0.5, 0.0); // drive forwards half speed
Wait(2.0); // for 2 seconds
myRobot.Drive(0.0, 0.0); // stop robot
}
/**
* Runs the motors with arcade steering.
*/
void OperatorControl(void)
{
myRobot.SetSafetyEnabled(true);
AxisCamera &robocam = AxisCamera::GetInstance();
robocam.WriteResolution((AxisCamera::Resolution_t)3);
robocam.WriteBrightness(0);
Wait(3.0);
while (IsOperatorControl())
{
myRobot.MecanumDrive_Cartesian(leftstick.GetX(), leftstick.GetY(), rightstick.GetY(), 0); //Mecanum drice, float x,float y, float rotation, gyro
bool GetTrigger(Joystick hand = leftstick);
if (!leftstick.GetTrigger()){
motors.Set(x));
}
else{
motors.Set(x/2);
}
robocam.GetImage();
image.GetImaqImage();
Wait(0.005); // wait for a motor update time
}
}
};
START_ROBOT_CLASS(RobotDemo);
Thanks for the help sorry to be a bothersum and ask so many question this is my first time using c++ ![]() |
|
#12
|
|||
|
|||
|
Re: Button programin C++
If you want it to toggle, (untested)
Code:
bool hasJoystickBeenClicked(Joystick &joystick, bool &prev, bool &cur) {
prev = cur;
cur = joystick.GetTrigger();
// Previous joystick value should be true (pressed trigger) and
// current one should be false (released trigger).
return (prev && !cur) ? true : false;
}
void getMotorSpeed(float &speed, bool half) {
return (half) ? speed / 2 : speed;
}
void toggleHalfSpeed(bool &half) {
half = !half;
}
// ...
if (hasJoystickBeenClicked(joystick, prev, cur))
toggleHalfSpeed(isHalfSpeed);
// ...
motor.Set(getMotorSpeed(speed, isHalfSpeed));
Last edited by basicxman : 23-01-2011 at 20:07. |
|
#13
|
|||
|
|||
|
void OperatorControl(void)
{ myRobot.SetSafetyEnabled(true); AxisCamera &robocam = AxisCamera::GetInstance(); robocam.WriteResolution((AxisCamera::Resolution_t) 3); robocam.WriteBrightness(0); Wait(3.0); while (IsOperatorControl()) { if (!leftstick.GetTrigger()){ myRobot.MecanumDrive_Cartesian(leftstick.GetX(), leftstick.GetY(), rightstick.GetY(), 0);// mecanum drive at full speed } else{ myRobot.MecanumDrive_Cartesian(leftstick.GetX()/2, leftstick.GetY()/2, rightstick.GetY()/2, 0);// mecanum drive at full speed } robocam.GetImage(); image.GetImaqImage(); Wait(0.005); // wait for a motor update time } Try this for your OperatorControl function. This should work for you. And have fun with the mecanum drive, it's alot of fun once you get used to driving it. |
|
#14
|
|||
|
|||
|
Re: Button programin C++
You just need to replace the motor.set() with myRobot.Drive().
Here is your code with the replacements made. It compiles. Code:
#include "WPILib.h"
#include "Vision/AxisCameraParams.h"
/**
* This is a demo program showing the use of the RobotBase class.
* The SimpleRobot 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.
*/
class RobotDemo : public SimpleRobot
{
RobotDrive myRobot; // robot drive system
Joystick leftstick; // only joystick
Joystick rightstick; // only joystick
HSLImage image;
public:
RobotDemo(void):
myRobot(1, 2, 3, 4), // these must be initialized in the same order
leftstick(1), // as they are declared above.
rightstick(2) // as they are declared above.
{
myRobot.SetExpiration(0.1);
}
/**
* Drive left & right motors for 2 seconds then stop
*/
void Autonomous(void)
{
myRobot.SetSafetyEnabled(false);
myRobot.Drive(0.5, 0.0); // drive forwards half speed
Wait(2.0); // for 2 seconds
myRobot.Drive(0.0, 0.0); // stop robot
}
/**
* Runs the motors with arcade steering.
*/
void OperatorControl(void)
{
myRobot.SetSafetyEnabled(true);
AxisCamera &robocam = AxisCamera::GetInstance();
robocam.WriteResolution((AxisCamera::Resolution_t)3);
robocam.WriteBrightness(0);
Wait(3.0);
while (IsOperatorControl())
{
myRobot.MecanumDrive_Cartesian(leftstick.GetX(), leftstick.GetY(), rightstick.GetY(), 0); //Mecanum drice, float x,float y, float rotation, gyro
bool GetTrigger(Joystick hand = leftstick);
if (!leftstick.GetTrigger()){
myRobot.Drive(1.0,0.0);
}
else{
myRobot.Drive(0.5,1.0);
}
robocam.GetImage();
image.GetImaqImage();
Wait(0.005); // wait for a motor update time
}
}
};
START_ROBOT_CLASS(RobotDemo);
|
|
#15
|
|||
|
|||
|
Re: Button programin C++
discokittys worked
random question for you guys, i know it is off the topic but... why isnt my camera sending an image to my driverstation? |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|