|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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);
|
|
#2
|
||||
|
||||
|
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);
|
|
#3
|
|||
|
|||
|
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?
|
|
#4
|
||||
|
||||
|
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); Code:
Motor.Set(0.5); |
|
#5
|
|||||
|
|||||
|
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,
Last edited by GeeTwo : 16-02-2015 at 00:25. Reason: nested lists |
|
#6
|
||||
|
||||
|
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);
}
|
|
#7
|
|||||
|
|||||
|
Re: Limit switch help
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.
|
|
#8
|
||||
|
||||
|
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());
...
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|