how do you program the limit switch so when it is touched you can only control the analog to go down but not go up(like does nothing when you push it). Also, i am having a problem about the motors, 2 motors are used on a 1:21 gear ratio, and we made two gears so there are 4 motors, when i test it, one side goes faster than the other side, and when i just push a little bit in, one side move and the other side doesnt. Is there any ways to fix that(all four motors are new). Thx for the help
I will assume that you are talking about driver control here, and by control the analog you probably mean a motor. This is very easy to do with an if else statement, included in the while loop that the rest of your driver control is in. Here is some basic pseudocode for what you are talking about.
while(true)
{
The rest of your driver control here
if(limit switch pressed)
Do what you want when the switch is pressed i.e. Move up
else
Do what you want when not pressed i.e. Move Down
}
For the motors not lifting in sync, this is most likely caused due to one side having more friction than the other. Depending on your lift type, make sure that the joints, slides, chain, etc. are the same on both sides. Adding structural supports connecting both sides together can also help, if you haven’t already.
i cant figure out what should i put in when the limit switch is on, like i want to disable the positive fuction of analog(or motor) when the limit switch is on
if(limit switch pressed)
{
[motor1] = 0
[motor2] = 0
}
I think you are over thinking it. All you need to do is set the motors off. If you want to turn them off.
If you want the switch to turn off positive power to the motor, but still allow negative power (while using joysticks) then you could make a variable that is equal to the joystick value. You could then only allow the motors to move IF the variable is less than zero…in other words…only allow it to go down.
I realize this isn’t EasyC, it is RobotC…but I imagine the same idea will apply and I’m hoping it will help you.
Here is a better example of what I think you want. Please read all the comments…I tried to explain what the code is doing. Please note, we are not expert coders. We are actually quite new to RobotC, but this code is functioning on our robot.
Here is a summary of what it does. We have one limit switch at the top of our elevator lift. When the switch is not being pressed, we have complete control over the lift…up…down. When we are not pushing the joystick, we have it set to run all lift motors at 8 power. This is to “hold” the lift in place.
When the lift is all the way up and hits the limit switch the code takes away our ability to run the motors at any more than 15 power. (We use 15 because it was a value that holds the lift at its highest point without sagging). But the code still allows us to run the lift down.
Hope this helps.
if (SensorValue[limitup] ==1) //if the limit switch at the top of our lift is pushed...do the following
{
if (vexRT[Ch2] < -10) //this reads channel 2 and only runs the following code if it is < -10. You could also put zero, but this is our "deadband".
{
motor[leftbottomlift] = vexRT[Ch2];
motor[leftmiddlelift] = vexRT[Ch2];
motor[lefttoplift] = vexRT[Ch2];
motor[rightbottomlift] = vexRT[Ch2];
motor[rightmiddlelift] = vexRT[Ch2];
motor[righttoplift] = vexRT[Ch2];
}
else if (vexRT[Ch2] > 10) //this reads channel 2 and only runs if the following code if it is > 10.
//this is what you want I think...we are running at 15 power to hold the lift...if you want to completely cut the power, just put zero.
{
motor[leftbottomlift] = 15;
motor[leftmiddlelift] = 15;
motor[lefttoplift] = 15;
motor[rightbottomlift] = 15;
motor[rightmiddlelift] = 15;
motor[righttoplift] = 15;
}
else //if the joystick is between -10 and +10 we hold the lift at 15 power. This keeps it from sagging.
{
motor[leftbottomlift] = 15;
motor[leftmiddlelift] = 15;
motor[lefttoplift] = 15;
motor[rightbottomlift] = 15;
motor[rightmiddlelift] = 15;
motor[righttoplift] = 15;
}
}
if (SensorValue[limitup] ==0) //if the limit switch is not pushed...do the following. Basically it gives us complete control...and holds the lift at 8 power if we are not moving the stick.
{
if (vexRT[Ch2] < -10)
{
motor[leftbottomlift] = vexRT[Ch2];
motor[leftmiddlelift] = vexRT[Ch2];
motor[lefttoplift] = vexRT[Ch2];
motor[rightbottomlift] = vexRT[Ch2];
motor[rightmiddlelift] = vexRT[Ch2];
motor[righttoplift] = vexRT[Ch2];
}
else if (vexRT[Ch2] > 10)
{
motor[leftbottomlift] = vexRT[Ch2];
motor[leftmiddlelift] = vexRT[Ch2];
motor[lefttoplift] = vexRT[Ch2];
motor[rightbottomlift] = vexRT[Ch2];
motor[rightmiddlelift] = vexRT[Ch2];
motor[righttoplift] = vexRT[Ch2];
}
else
{
motor[leftbottomlift] = 8;
motor[leftmiddlelift] = 8;
motor[lefttoplift] = 8;
motor[rightbottomlift] = 8;
motor[rightmiddlelift] = 8;
motor[righttoplift] = 8;
}
}