Go to Post 20,000 students 900 teams robots Gracious professionalism = FIRST - Bcahn836 [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 07-02-2015, 22:30
PredaFran PredaFran is offline
Amateur Programmer
AKA: Francisco
FRC #5285 (Sea Kings Robotics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: California
Posts: 25
PredaFran is an unknown quantity at this point
Post Help with toggle-button

We would like to be able to press a button in the joystick, and that for example if the joystick was controlling motor 1, it would control motor 2.
Thanks in advance.

Last edited by PredaFran : 07-02-2015 at 22:36.
Reply With Quote
  #2   Spotlight this post!  
Unread 08-02-2015, 00: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: Help with toggle-button

My team does type of action for our dual acting solenoid.

Code:
bool isReady;
bool Piston;

isReady = true;
Piston = false; 


if (DriverJoyStick.GetTrigger() && isReady && !Piston){
		Piston = true;
		isReady = false;
} else if (DriverJoyStick.GetTrigger() && isReady && Piston {
		Piston = false;
		isReady = false;
} else if (!DriverJoyStick.GetTrigger()){
		isReady = true;
}
Where when you press the DriverJoystick Trigger and release it, it toggles the Boolean HalfSpeed. The Boolean you can set later in your code. We use it such as.

Code:
if(Piston){
	piston.Set(Relay::kForward);
} else if (!Piston){
	piston.Set(Relay::kReverse);
}
Reply With Quote
  #3   Spotlight this post!  
Unread 08-02-2015, 00:50
PredaFran PredaFran is offline
Amateur Programmer
AKA: Francisco
FRC #5285 (Sea Kings Robotics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: California
Posts: 25
PredaFran is an unknown quantity at this point
Re: Help with toggle-button

Could you give me more info about it? or a simpler version using two motors only?
Thanks in advance
Reply With Quote
  #4   Spotlight this post!  
Unread 08-02-2015, 01:26
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: Help with toggle-button

All you would have to change is this part of the code assuming you keep Booleons named the same:

Code:
if(Piston){
	piston.Set(Relay::kForward);
} else if (!Piston){
	piston.Set(Relay::kReverse);
}
To something like this:

Code:
if(Piston){
	Talon1.Set(Stick.GetY()); // Where as the talon1 would be controlled by the Y axis of the Joystick
} else if (!Piston){
	Talon2.Set(Stick.GetY());// Where as another talon, talon2, would be controlled by the Y axis of the Joystick
}
Reply With Quote
  #5   Spotlight this post!  
Unread 08-02-2015, 16:53
PredaFran PredaFran is offline
Amateur Programmer
AKA: Francisco
FRC #5285 (Sea Kings Robotics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: California
Posts: 25
PredaFran is an unknown quantity at this point
Re: Help with toggle-button

i have this code so far, i cant get it to work, any idea of what could be wrong?



Code:
#include "WPILib.h"

class Robot: public SampleRobot
{
	bool Piston;
	Joystick stick; // joystick

	Piston = false; 
	Talon m_motor1;
	Talon m_motor2;
public:
	Robot() :
		m_motor1(1),	
		stick(0)
}

{
		myRobot.SetExpiration(0.1);
	
}
	if(Piston){
		m_motor1.Set(Stick.GetY()); // Where as the talon1 would be controlled by the Y axis of the Joystick
	} else if (!Piston){
		m_motor2.Set(Stick.GetY());// Where as another talon, talon2, would be controlled by the Y axis of the Joystick
	}





};

START_ROBOT_CLASS(Robot);
Reply With Quote
  #6   Spotlight this post!  
Unread 08-02-2015, 18:17
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Help with toggle-button

Quote:
Originally Posted by PredaFran View Post
i have this code so far, i cant get it to work, any idea of what could be wrong?
You left out the part where you read the joystick button and set the flag you're calling Piston. It's always going to be false.
Reply With Quote
  #7   Spotlight this post!  
Unread 08-02-2015, 18:22
PredaFran PredaFran is offline
Amateur Programmer
AKA: Francisco
FRC #5285 (Sea Kings Robotics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: California
Posts: 25
PredaFran is an unknown quantity at this point
Re: Help with toggle-button

could you give me a hand with it? im still new in the field of c++ robotics.
Thanks in advance
Reply With Quote
  #8   Spotlight this post!  
Unread 08-02-2015, 18:45
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Help with toggle-button

tomy's first reply to you gave the toggle code you are looking for.
Reply With Quote
  #9   Spotlight this post!  
Unread 08-02-2015, 19:00
PredaFran PredaFran is offline
Amateur Programmer
AKA: Francisco
FRC #5285 (Sea Kings Robotics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: California
Posts: 25
PredaFran is an unknown quantity at this point
Re: Help with toggle-button

thanks for the reply, but i dont quite get what im supposed to do
Thanks in advance
Reply With Quote
  #10   Spotlight this post!  
Unread 08-02-2015, 19:51
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Help with toggle-button

I'm not skilled enough with C++ to help you in this kind of back-and-forth forum posting. It seems likely that your level of understanding is such that you would be best served by someone helping you in person. Do you know any other teams in the Long Beach area?
Reply With Quote
  #11   Spotlight this post!  
Unread 09-02-2015, 01:54
PredaFran PredaFran is offline
Amateur Programmer
AKA: Francisco
FRC #5285 (Sea Kings Robotics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: California
Posts: 25
PredaFran is an unknown quantity at this point
Re: Help with toggle-button

Unfortunately, I don't thanks for the help tho
Any thing you think i should read to get more informed in the subject or another place to get help from are appreciated
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:07.

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