Go to Post Patience, grasshopper. They'll get to it. - Rick TYler [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 15-02-2015, 15:58
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
Limit switch help

im trying to create a code that needs to stop a motor from moving and move it backwards for a short time, when a limit switch is pressed, first we are trying to start a motor using a limit switch, but we cant, any help is appreciated.




Code:
#include "WPILib.h"


class Robot: public SampleRobot
{
	Talon Motor;
    DigitalInput limitSwitch;


public:
	 Robot():

	limitSwitch(1),
	Motor(6)

	{

	}


	void OperatorControl()
	{
		while (IsOperatorControl() && IsEnabled())
		{

			if(limitSwitch.Get()>0)
            {

         			
			Set.Motor(1.5,0);

            }
        }
	}

};

START_ROBOT_CLASS(Robot);
Reply With Quote
  #2   Spotlight this post!  
Unread 15-02-2015, 18:17
nandeeka's Avatar
nandeeka nandeeka is offline
Registered User
FRC #1868
Team Role: Programmer
 
Join Date: May 2014
Rookie Year: 2013
Location: United States
Posts: 53
nandeeka is on a distinguished road
Re: Limit switch help

Firstly, you need to say Motor.Set() instead of Set.Motor(). Also, you are giving the motor a speed of 1.5, when the range of values possible is {-1.0, 1.0}. Finally, a digital input returns a boolean, so you should be checking if the limit switch value is true instead of if it is greater than 0.

Last edited by nandeeka : 15-02-2015 at 18:19.
Reply With Quote
  #3   Spotlight this post!  
Unread 15-02-2015, 18:27
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: Limit switch help

can you give me a hand with the bool?

Code:
#include "WPILib.h"


class Robot: public SampleRobot
{
	Talon Motor;
    DigitalInput limitSwitch;
    bool limitValue

public:
	 Robot():

	limitSwitch(1),
	Motor(6)

	{

	}

	 

	void OperatorControl()
	{
		while (IsOperatorControl() && IsEnabled())
		{
         	if(limitSwitch.Get()=1)
            {
			Motor.Set(1.0);
         	Wait(0.005);
            }
     


		}

	}

};

START_ROBOT_CLASS(Robot);
Reply With Quote
  #4   Spotlight this post!  
Unread 15-02-2015, 18:33
nandeeka's Avatar
nandeeka nandeeka is offline
Registered User
FRC #1868
Team Role: Programmer
 
Join Date: May 2014
Rookie Year: 2013
Location: United States
Posts: 53
nandeeka is on a distinguished road
Re: Limit switch help

Try something like this:

Code:
#include "WPILib.h"


class Robot: public SampleRobot
{
	Talon Motor;
    DigitalInput limitSwitch;

public:
	 Robot():

	limitSwitch(1),
	Motor(6)

	{

	}

	 

	void OperatorControl()
	{
		while (IsOperatorControl() && IsEnabled())
		{
         	      if(limitSwitch.Get()) {
			     Motor.Set(1.0);
                             Wait(0.005);
                      }
                 }

	}

};

START_ROBOT_CLASS(Robot);
limitSwitch.Get() returns a boolean (true if the limit switch is pressed, false if it isn't). If you want it to move when the limit switch is pressed, then you want to move when the get method is returning true.
Reply With Quote
  #5   Spotlight this post!  
Unread 15-02-2015, 18: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: Limit switch help

the motors do not stop when the limit switch is pressed, we double checked the cables and all to make sure it isnt the code,any idea of what could be wrong?
Reply With Quote
  #6   Spotlight this post!  
Unread 15-02-2015, 21:42
nandeeka's Avatar
nandeeka nandeeka is offline
Registered User
FRC #1868
Team Role: Programmer
 
Join Date: May 2014
Rookie Year: 2013
Location: United States
Posts: 53
nandeeka is on a distinguished road
Re: Limit switch help

If you are trying to stop the motor when the limit switch is pressed, use this line of code:
Code:
Motor.Set(0.0);
If you are trying to start the motor when the limit switch is pressed, use this line of code:

Code:
Motor.Set(0.5);
Reply With Quote
  #7   Spotlight this post!  
Unread 16-02-2015, 00:24
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,654
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Limit switch help

Also, check that the switches are working. Depending on your specific setup, a generic way to include a monitor of Switch.get() on your smart dashboard. Then unplug your motors but otherwise run the robot. Then,
  1. Manually engage the limit switch to see if the result gets to the robot
  2. If not, unplug the switch and test for continuity each way...
  3. If so, manually move the actuator so that the limit switch should engage/disengage. Does it?
    • If so, look for software issues
    • If not, look for hardware issues - specifically mechanical adjustments so that the switch engages/disengages at the right time.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.

Last edited by GeeTwo : 16-02-2015 at 00:25. Reason: nested lists
Reply With Quote
  #8   Spotlight this post!  
Unread 17-02-2015, 23:09
teslalab2's Avatar
teslalab2 teslalab2 is offline
RogueBotix LLC
VRC #8091
Team Role: Mentor
 
Join Date: Feb 2015
Rookie Year: 2014
Location: Austin MN
Posts: 109
teslalab2 will become famous soon enoughteslalab2 will become famous soon enough
Re: Limit switch help

Are you limit switches wired correctly? the switch needs to be wired from signal too ground. the signal pin is held high until you ground it. so the value that you read will be inverted. you either need to rewire the switch, or put a not in front of the limit switch, such as

Code:
If(!limitswitch.Get())
{
motor.Set(.5);
Wait(sometime);
motor.Set(0);
}
Reply With Quote
  #9   Spotlight this post!  
Unread 18-02-2015, 01:29
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,654
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Limit switch help

Quote:
Originally Posted by teslalab2 View Post
Code:
If(!limitswitch.Get())
{
motor.Set(.5);
Wait(sometime);
motor.Set(0);
}
Is the Wait() in WPIlib multi-thread friendly? Not being sure, I have advised our programmers against using it, but depending on somewhat more histrionic timeout measures.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #10   Spotlight this post!  
Unread 18-02-2015, 02:13
bob.wolff68's Avatar
bob.wolff68 bob.wolff68 is offline
Da' Mentor Man
FRC #1967
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2007
Location: United States
Posts: 157
bob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nice
Re: Limit switch help

It's multi-thread friendly, but there's no additional thread here. I think he's ok to do the Wait (small) at the moment - first things first ... an ability to know the switch is working right. I'd suggest not worrying about the motor control yet. I'd say use the smart dashboard to put the value of the limit switch up on the dashboard and see it flitter from 1 to 0 when it is closed and opened.

Code:
SmartDashboard::PutNumber("Switch1", limitswitch.Get());
...
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
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 14:51.

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