549 views

# Limit Switch Programming

1. 4 months ago

### Yuma123

Feb 7
Edited 4 months ago by Yuma123

So I am trying to program limit switches so my 4 bar doesn't go too far up and down. I'm doing this to my Double Reverse 4 Bar but only for the way down. I have a pic of the program right now and the 4 bar doesn't stop when it hits the limit switch, and the DR4B only goes up. Is this my programming issue or a mechanical issue?
Thanks

2. ### [SPR] JP

Feb 7 Texas PANDA
Edited 4 months ago by [SPR] JP

There’s no code

3. ### Yuma123

Feb 7

@SkinnyPanda Robotics There’s no code

i just posted the code

4. ### [SPR] JP

Feb 7 Texas PANDA

@Yuma123 i just posted the code

Lols

5. ### ZachDaChampion

Feb 7 Fort Lauderdale, Florida 77788J

The logic is sound, but the syntax is `SensorValue[sensor]`, not `SensorValue(sensor)`. That should fix it.

6. ### [SPR] JP

Feb 7 Texas PANDA
Edited 4 months ago by [SPR] JP

Ok here’s how I would recommend doing it from current code we have competed with:
if(vexRT[Btn6U] == 1)
{
if(SensorValue(Up4Bar) == 1)
{
motor[L4Bar] = 0;
motor[R4Bar] = 0;
}
else
{
motor[L4Bar] = 127;
motor[R4Bar] = 127;
}
}
else if(vexRT[Btn6D] == 1)
{
if(SensorValue(Down4Bar) == 1)
{
motor[L4Bar] = 0;
motor[R4Bar] = 0;
}
else
{
motor[L4Bar] = -127;
motor[R4Bar] = -127;
}
}
else
{
motor[L4Bar] = 0;
motor[R4Bar] = 0;
}

@ZachDaChampion The logic is sound, but the syntax is `SensorValue[sensor]`, not `SensorValue(sensor)`. That should fix it.

That’s how I’ve always done it and never had a problem.

7. ### [SPR] JP

Feb 7 Texas PANDA

I know it’s not pretty... but just see if it works

8. ### Yuma123

Feb 7

@SkinnyPanda Robotics I know it’s not pretty... but just see if it works

should the sensor name be in brackets instead of parenthesis

9. ### [SPR] JP

Feb 7 Texas PANDA

@Yuma123 should the sensor name be in brackets instead of parenthesis

It shouldn’t matter at all.

10. ### Barin

Feb 7 Arizona

@SkinnyPanda Robotics

@ZachDaChampion The logic is sound, but the syntax is `SensorValue[sensor]`, not `SensorValue(sensor)`. That should fix it.

That’s how I’ve always done it and never had a problem.

That doesn't mean your syntax is correct. RobotC is quite forgiving about these things, but you should still strive to use the correct syntax: `SensorValue[]`

11. ### [SPR] JP

Feb 7 Texas PANDA

@Barin That doesn't mean your syntax is correct. RobotC is quite forgiving about these things, but you should still strive to use the correct syntax: `SensorValue[]`

I never said I was right, just that it shouldn’t matter.

12. ### Vex 9185

Feb 7 Bellefontaine, Ohio 9185B

@Barin That doesn't mean your syntax is correct. RobotC is quite forgiving about these things, but you should still strive to use the correct syntax: `SensorValue[]`

The thing I find odd is that RobotC's sample programs use SensorValue() while their Online Wiki says "short sensorValue[tSensors sensor]"

13. ### [TVA]Connor

Feb 7 South Texas 1814D
Edited 4 months ago by [TVA]Connor

As what I can see, there doesn't seem to be any issues with the code (unless someone can prove me otherwise). When a sensor isn't connected, there should either be a value of 1 or -1, so probably I think that what's happening is that either one of your limit switches aren't connected in the correct port, isn't plugged in, or a wire could be potentially damaged.
This is just my inference though, but hopefully this helps :D
- [TVA] Connor

14. ### [SPR] JP

Feb 7 Texas PANDA

@[TVA Connor]As what I can see, there doesn't seem to be any issues with the code (unless someone can prove me otherwise). When a sensor isn't connected, there should either be a value of 1 or -1, so probably I think that what's happening is that either one of your limit switches aren't connected in the correct port, isn't plugged in, or a wire could be potentially damaged.
This is just my inference though, but hopefully this helps :D
- [TVA] Connor

Oh if sensors output 1 or -1 and not 0 or 1 then that’s the problem.

15. ### Yuma123

Feb 7

@SkinnyPanda Robotics Ok here’s how I would recommend doing it from current code we have competed with:
if(vexRT[Btn6U] == 1)
{
if(SensorValue(Up4Bar) == 1)
{
motor[L4Bar] = 0;
motor[R4Bar] = 0;
}
else
{
motor[L4Bar] = 127;
motor[R4Bar] = 127;
}
}
else if(vexRT[Btn6D] == 1)
{
if(SensorValue(Down4Bar) == 1)
{
motor[L4Bar] = 0;
motor[R4Bar] = 0;
}
else
{
motor[L4Bar] = -127;
motor[R4Bar] = -127;
}
}
else
{
motor[L4Bar] = 0;
motor[R4Bar] = 0;
}

That’s how I’ve always done it and never had a problem.

The program unfortunately didn't work

16. ### [SPR] JP

Feb 7 Texas PANDA

That’s odd. Did anything happen at all?

17. ### Yuma123

Feb 7
Edited 4 months ago by Yuma123

@SkinnyPanda Robotics That’s odd. Did anything happen at all?

Uh the 4 bar continued to go down after hitting the limit switch
NVM it worked. i must have typed it in wrong

18. ### [SPR] JP

Feb 7 Texas PANDA

Oh wait my program worked?

19. ### Yuma123

Feb 7
Edited 4 months ago by Yuma123

@SkinnyPanda Robotics Oh wait my program worked?

Ya, but it didnt work for the DR4B
Any clue on why that is?

20. ### [SPR] JP

Feb 8 Texas PANDA

Debug the values the limit switches output when pressed and unpressed. Make sure the codes calls those values.