Me and my team are trying to program Integrated Encoder Modules for the first time and would like to know if there is a way to program the robot to do a certain action with the press of a button say for example lift a scissor lift to a certain height with a click of a button not in autonomous using easy c.
For an easy example
Motor=127
Waituntil (sensorvalue[sensorname]>whatevervalue)
Motor=0
Ignore formating, in robotc there is a context menu that explains almost every function there is, i can post an update on how to enable it, however this code should work for almost every aplication, with minor adjustments like name of sensors and motors.
how about this
while (sensorvalue[sensorname]>whatevervalue){
Motor=127
}
while (sensorvalue[sensorname]<whatevervalue){
Motor=0
}
so that you could also reset the sensor if you wanted to rerun it
you could do that, however using whiles means you can only do that thing, and nothing else until your sensor is through
Although this seems pretty simple, it’s actually a bit more complicated than you’d think. Are you trying to make the system be a toggle where you press it once and it holds the position you program it for, then you press it again and then you can be able to gain back control of the lift? Or are you trying to have a button where you press it once; in which by that press it removes your control of the lift, goes to that position, then gives you control again? (I’m not good with easyc but at least I can give you pseudocode).
of course, you could just make a simple P loop, for example. This will allow you to have a constant value that your lift will instantly go to, this means your lift won’t fall, and will remain at the value until you set target to a different number, or the motors stall.
float P;
short error;
short target;
byte motorpower;
task Ploop();
{ P=.05;//you can change this to whatever however the number will be good at a certain value
while(true)
{
if (vexRT(btn8l)==1
{
error=(target-sensorvalue)
motorpower=(error*P)
}
if(motorpower>127)
{
motorpower=127;
}
if(motorpower<-127)
{
motorpower=-127
}
motor[Scissor]=motorpower;
}
}
The second one I am trying to set different height buttons to the point where every button takes you to a different height but I would still like some control of the robot
of course, you could just make a simple P loop, for example. This will allow you to have a constant value that your lift will instantly go to, this means your lift won’t fall, and will remain at the value until you set target to a different number, or the motors stall.
float P;
short error;
short target;
byte motorpower;
task Ploop();
{ P=2.0;//you can change this to whatever however the number will be good at a certain value
while(true)
{
if (vexRT(btn8l)==1
{
error=(target-sensorvalue)
motorpower=(error*P)
}
if(motorpower>127)
{
motorpower=127;
}
if(motorpower<-127)
{
motorpower=-127
}
motor[Scissor]=motorpower;
wait1msec(25);
}
}
task main();
{
starttask(ploop);
if(vexRT[btn8d]==1)
{
target=100//or whatever it wouldve been
}
if (vexRT[btn8L]==1)
{
target=0//or whatever you want your other target to be
}
}
This code auto gives power based on how far away something is, meaning all you have to do is set target and it will go as fast as possible to the target, and slow down as it nears the target.