Go to Post Just because you can doesn't mean you should. - pfreivald [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
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-02-2016, 10:25
nlt5 nlt5 is offline
Registered User
FRC #5676
 
Join Date: Feb 2016
Location: Michigan
Posts: 23
nlt5 is an unknown quantity at this point
Button coding

Can someone help me with the code that would be used to have a motor come on when a button is pressed. I can get the motors to turn on and off with the press of a button but I want the motor to run while the button is pressed then when the button is released the motor stops.

Thanks for all the help on this forum,
what a great resource for new teams.

Oh and I am using iterative
Reply With Quote
  #2   Spotlight this post!  
Unread 23-02-2016, 10:29
Pratik Kunapuli's Avatar
Pratik Kunapuli Pratik Kunapuli is offline
Probably browning-out on Astro-Turf
FRC #1648 (G3 Robotics)(EWCP)
Team Role: Mentor
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Atlanta, GA
Posts: 143
Pratik Kunapuli is a name known to allPratik Kunapuli is a name known to allPratik Kunapuli is a name known to allPratik Kunapuli is a name known to allPratik Kunapuli is a name known to allPratik Kunapuli is a name known to all
Re: Button coding

Code:
if(joystick.getRawButton(buttonNumber)
{
    speedController.set(1.0);
}
else
{
    speedController.set(0.0);
}
If this code is in the periodic teleop method, it should do what you want.
__________________
Official Driving Record: 101-59-0
2012-2015 Student 341 Miss Daisy
2015-Current Mentor 1648 G3 Robotics

Last edited by Pratik Kunapuli : 23-02-2016 at 10:31.
Reply With Quote
  #3   Spotlight this post!  
Unread 23-02-2016, 10:31
nlt5 nlt5 is offline
Registered User
FRC #5676
 
Join Date: Feb 2016
Location: Michigan
Posts: 23
nlt5 is an unknown quantity at this point
Re: Button coding

Great,
thank you very much
Reply With Quote
  #4   Spotlight this post!  
Unread 24-02-2016, 07:58
nlt5 nlt5 is offline
Registered User
FRC #5676
 
Join Date: Feb 2016
Location: Michigan
Posts: 23
nlt5 is an unknown quantity at this point
Re: Button coding

So I wrote the code and was able to get this to work for the motors in one direction. I would press and hold the button, the motors would spin, and when I released the button they would stop. We want the motors to spin in both directions so I wrote additional code and set the motors to -1 using a different button. When I ran the code the motor would pulse at different rotational rates. When I would program to use 2 buttons, one for on, one for off the pulsing would stop. Any ideas??? I'm not sure why in one direction the motor spins fine but in the other they pulse.

thanks
Reply With Quote
  #5   Spotlight this post!  
Unread 24-02-2016, 09:13
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,025
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Button coding

Quote:
Originally Posted by nlt5 View Post
I wrote additional code and set the motors to -1 using a different button. When I ran the code the motor would pulse at different rotational rates.
This sounds like the common coding error where one button is commanding the motor to go while the other is commanding it to stop.

You need to change your if/then/else logic so that only one command is issued to the motor(s).


if your code looks something like this:
Code:
if (button1) {setmotor(1)} else setmotor(0);

if (button2) {setmotor(-1)} else setmotor(0);


... then change it to this:
Code:
if (button1) {setmotor(1)} 
else 
if (button2) {setmotor(-1)}
else setmotor(0);



Last edited by Ether : 24-02-2016 at 09:17.
Reply With Quote
  #6   Spotlight this post!  
Unread 24-02-2016, 12:15
nlt5 nlt5 is offline
Registered User
FRC #5676
 
Join Date: Feb 2016
Location: Michigan
Posts: 23
nlt5 is an unknown quantity at this point
Re: Button coding

Sounds good,
I will test in about a month when it is legal to unbag our robot.

Thank you very much.
Reply With Quote
  #7   Spotlight this post!  
Unread 28-02-2016, 11:41
Potatonator's Avatar
Potatonator Potatonator is offline
much potato very robot wow
FRC #4360 (Spudnik)
 
Join Date: Feb 2014
Rookie Year: 2012
Location: Moorhead, MN
Posts: 15
Potatonator is an unknown quantity at this point
Re: Button coding

Quote:
Originally Posted by Pratik Kunapuli View Post
Code:
if(joystick.getRawButton(buttonNumber)
{
    speedController.set(1.0);
}
else
{
    speedController.set(0.0);
}
If this code is in the periodic teleop method, it should do what you want.
Is there any way to set this to run from multiple joysticks? For instance, having button 1 on joystick 1 start and button one on joystick 2 stop it?
Reply With Quote
  #8   Spotlight this post!  
Unread 28-02-2016, 13:54
Pratik Kunapuli's Avatar
Pratik Kunapuli Pratik Kunapuli is offline
Probably browning-out on Astro-Turf
FRC #1648 (G3 Robotics)(EWCP)
Team Role: Mentor
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Atlanta, GA
Posts: 143
Pratik Kunapuli is a name known to allPratik Kunapuli is a name known to allPratik Kunapuli is a name known to allPratik Kunapuli is a name known to allPratik Kunapuli is a name known to allPratik Kunapuli is a name known to all
Re: Button coding

Quote:
Originally Posted by Potatonator View Post
Is there any way to set this to run from multiple joysticks? For instance, having button 1 on joystick 1 start and button one on joystick 2 stop it?
You could do it like this:

Code:
if(joystick1.getRawButton(buttonNumber)
{
    speedController.set(1.0);
}
else if(joystick2.getRawButton(buttonNumber)
{
    speedController.set(0.0);
}
__________________
Official Driving Record: 101-59-0
2012-2015 Student 341 Miss Daisy
2015-Current Mentor 1648 G3 Robotics
Reply With Quote
  #9   Spotlight this post!  
Unread 28-02-2016, 14:25
Potatonator's Avatar
Potatonator Potatonator is offline
much potato very robot wow
FRC #4360 (Spudnik)
 
Join Date: Feb 2014
Rookie Year: 2012
Location: Moorhead, MN
Posts: 15
Potatonator is an unknown quantity at this point
Re: Button coding

Thank you. Looks like it's working.
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 08:54.

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