Launcher/hang program help

For the competition StarStruck, my and my teams launch is a gear system with touchsensors to lift the launch, and then another touchsensor to lower it. We also have a high hang, which is programmed to 2 buttons to lift and lower. Could you tell me if my program will work the way i want it to?


#pragma config(Sensor, dgtl1, touchsensor1, sensorTouch)
#pragma config(Sensor, dgtl2, touchsensor2, sensorTouch)
#pragma config(Motor, port2, wheel1, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port3, lift, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, wheel2, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, lift, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, launch1, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, launch2, tmotorVex393_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
  while(1==1)
    {
    if(SensorValue(touchsensor1) == 1 )
      {
      motor[port6] = 127;
      motor[port7] = 127;

      if(SensorValue(touchsensor2) == 1 )
        {
        motor[port6] = -127;
        motor[port7] = -127;

        motor[port2] = vexRT[Ch3];
        motor[port4] = vexRT[Ch2];

        if(vexRT[Btn6U] ==1)
          {
          motor[port5] = 127;
          motor[port3] = 127;
          }

        if(vexRT[Btn6D] ==1)
          {
          motor[port3] = -127;
          motor[port5] = -127;
          }
        else
          {
          motor[port3] = 0;
          motor[port5] = 0;
          }
        }
      }
    }
}

I reformatted you code to make it a little easier to read, it’s probably not going to work the way you want it to at the moment, I will move this thread into the general forum so the community can comment and, hopefully, give you some help.

One thing I noticed is that you don’t contain an “else if” statement after the first “if”. Another is that you should use brackets to describe motors AND sensors. (Example “SensorValue[touchsensor2]”)
Here’s a your code tweaked:


#pragma config(Sensor, dgtl1, touchsensor1, sensorTouch)
#pragma config(Sensor, dgtl2, touchsensor2, sensorTouch)
#pragma config(Motor, port2, wheel1, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port3, lift, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, wheel2, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, lift, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, launch1, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, launch2, tmotorVex393_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
  while(1==1)
    {
    if(SensorValue[touchsensor1] == 1 )
      {
      motor[port6] = 127;
      motor[port7] = 127;

      if(SensorValue[touchsensor2] == 1 )
        {
        motor[port6] = -127;
        motor[port7] = -127;

        motor[port2] = vexRT[Ch3];
        motor[port4] = vexRT[Ch2];

        else if(vexRT[Btn6U] ==1)
          {
          motor[port5] = 127;
          motor[port3] = 127;
          }

        else if(vexRT[Btn6D] ==1)
          {
          motor[port3] = -127;
          motor[port5] = -127;
          }
        else
          {
          motor[port3] = 0;
          motor[port5] = 0;
          }
        }
      }
    }
}

Note: I may need more information and probably some pictures to allow me to be able to see if there’s anymore changes. I also noticed a strange ‘fighting’ or a clash of two similar things set at different values, is it fine if I try to remake the code?

I messed with some curly-bracket placing, and I messed with the logic statements:


#pragma config(Sensor, dgtl1, touchsensor1, sensorTouch)
#pragma config(Sensor, dgtl2, touchsensor2, sensorTouch)
#pragma config(Motor, port2, wheel1, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port3, lift, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, wheel2, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, lift, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, launch1, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, launch2, tmotorVex393_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
  while(1==1)
    {
    if(SensorValue[touchsensor1] == 1 )
      {
      motor[port6] = 127;
      motor[port7] = 127;
}
      else if(SensorValue[touchsensor2] == 1 )
        {
        motor[port6] = -127;
        motor[port7] = -127;

        motor[port2] = vexRT[Ch3];
        motor[port4] = vexRT[Ch2];
}
        if(vexRT[Btn6U] ==1)
          {
          motor[port5] = 127;
          motor[port3] = 127;
          }

        else if(vexRT[Btn6D] ==1)
          {
          motor[port3] = -127;
          motor[port5] = -127;
          }
        else
          {
          motor[port3] = 0;
          motor[port5] = 0;
      }
    }
}

Note: It seems that there isn’t a button to control the catapult and lift, is there supposed to be one?