Limit Switch Programming


#1

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
Pic of Program.PNG


#2

There’s no code
Oh it just loaded


#3

i just posted the code


#4

Lols


#5

The logic is sound, but the syntax is


SensorValue[sensor]

, not


SensorValue(sensor)

. That should fix it.


#6

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.


#7

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


#8

should the sensor name be in brackets instead of parenthesis


#9

It shouldn’t matter at all.


#10

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

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


#12

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


#13

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 :smiley:

  • [TVA] Connor

#14

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


#15

The program unfortunately didn’t work


#16

That’s odd. Did anything happen at all?


#17

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


#18

Oh wait my program worked?


#19

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


#20

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