Go to Post If it's not on fire, it's a software problem. - Matt Leese [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 23-01-2011, 16:25
tomy tomy is offline
Registered User
FRC #3038 (I.C.E. Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Stacy, Minnesota
Posts: 494
tomy has a spectacular aura abouttomy has a spectacular aura about
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);
if im right that checks if the trigger on the left joystick it pushed or not.
i was trying to create an if statement to change the speed of the motors but its not working.

any suggestions?
Reply With Quote
  #2   Spotlight this post!  
Unread 23-01-2011, 18:33
krudeboy51's Avatar
krudeboy51 krudeboy51 is offline
Only Programmer
AKA: kory
FRC #0369 (369)
Team Role: Programmer
 
Join Date: Mar 2010
Rookie Year: 2010
Location: brooklyn
Posts: 151
krudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of light
Send a message via AIM to krudeboy51
Re: Button programin C++

..

Last edited by krudeboy51 : 23-01-2011 at 19:46.
Reply With Quote
  #3   Spotlight this post!  
Unread 23-01-2011, 18:42
tomy tomy is offline
Registered User
FRC #3038 (I.C.E. Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Stacy, Minnesota
Posts: 494
tomy has a spectacular aura abouttomy has a spectacular aura about
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?
Reply With Quote
  #4   Spotlight this post!  
Unread 23-01-2011, 19:16
krudeboy51's Avatar
krudeboy51 krudeboy51 is offline
Only Programmer
AKA: kory
FRC #0369 (369)
Team Role: Programmer
 
Join Date: Mar 2010
Rookie Year: 2010
Location: brooklyn
Posts: 151
krudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of light
Send a message via AIM to krudeboy51
Re: Button programin C++

..

Last edited by krudeboy51 : 23-01-2011 at 19:45.
Reply With Quote
  #5   Spotlight this post!  
Unread 23-01-2011, 19:22
DiscoKittyPrime DiscoKittyPrime is offline
Registered User
AKA: Joshua Bryant
FRC #0057 (Leopards)
Team Role: Programmer
 
Join Date: Dec 2010
Rookie Year: 2003
Location: Houston, Tx
Posts: 26
DiscoKittyPrime will become famous soon enough
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.
Reply With Quote
  #6   Spotlight this post!  
Unread 23-01-2011, 19:28
tomy tomy is offline
Registered User
FRC #3038 (I.C.E. Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Stacy, Minnesota
Posts: 494
tomy has a spectacular aura abouttomy has a spectacular aura about
Re: Button programin C++

That's what I ment thanks
Reply With Quote
  #7   Spotlight this post!  
Unread 23-01-2011, 19:35
tomy tomy is offline
Registered User
FRC #3038 (I.C.E. Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Stacy, Minnesota
Posts: 494
tomy has a spectacular aura abouttomy has a spectacular aura about
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
Reply With Quote
  #8   Spotlight this post!  
Unread 23-01-2011, 19:41
DiscoKittyPrime DiscoKittyPrime is offline
Registered User
AKA: Joshua Bryant
FRC #0057 (Leopards)
Team Role: Programmer
 
Join Date: Dec 2010
Rookie Year: 2003
Location: Houston, Tx
Posts: 26
DiscoKittyPrime will become famous soon enough
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.
Reply With Quote
  #9   Spotlight this post!  
Unread 23-01-2011, 19:45
tomy tomy is offline
Registered User
FRC #3038 (I.C.E. Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Stacy, Minnesota
Posts: 494
tomy has a spectacular aura abouttomy has a spectacular aura about
Re: Button programin C++

it dosent like motors.set(x)

do i have to declare each motor

leftmotor.set(x),rightmotor....
Reply With Quote
  #10   Spotlight this post!  
Unread 23-01-2011, 19:52
DiscoKittyPrime DiscoKittyPrime is offline
Registered User
AKA: Joshua Bryant
FRC #0057 (Leopards)
Team Role: Programmer
 
Join Date: Dec 2010
Rookie Year: 2003
Location: Houston, Tx
Posts: 26
DiscoKittyPrime will become famous soon enough
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.
Reply With Quote
  #11   Spotlight this post!  
Unread 23-01-2011, 20:00
tomy tomy is offline
Registered User
FRC #3038 (I.C.E. Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Stacy, Minnesota
Posts: 494
tomy has a spectacular aura abouttomy has a spectacular aura about
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++
Reply With Quote
  #12   Spotlight this post!  
Unread 23-01-2011, 20:01
basicxman basicxman is offline
Emily Horsman
FRC #2200 (MMRambotics)
Team Role: Programmer
 
Join Date: Oct 2007
Rookie Year: 2007
Location: Burlington, Ontario
Posts: 971
basicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant future
Send a message via AIM to basicxman Send a message via MSN to basicxman Send a message via Yahoo to basicxman
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));
EDIT: More code.

Last edited by basicxman : 23-01-2011 at 20:07.
Reply With Quote
  #13   Spotlight this post!  
Unread 23-01-2011, 20:15
DiscoKittyPrime DiscoKittyPrime is offline
Registered User
AKA: Joshua Bryant
FRC #0057 (Leopards)
Team Role: Programmer
 
Join Date: Dec 2010
Rookie Year: 2003
Location: Houston, Tx
Posts: 26
DiscoKittyPrime will become famous soon enough
Talking Re: Button programin C++

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.
Reply With Quote
  #14   Spotlight this post!  
Unread 23-01-2011, 20:17
jwakeman jwakeman is offline
Registered User
FRC #0063 (Red Barons)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: 16510
Posts: 182
jwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nice
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);
Reply With Quote
  #15   Spotlight this post!  
Unread 23-01-2011, 20:21
tomy tomy is offline
Registered User
FRC #3038 (I.C.E. Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Stacy, Minnesota
Posts: 494
tomy has a spectacular aura abouttomy has a spectacular aura about
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?
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:34.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi