ROBOTC.net forums
http://robotc.net/forums/

Start Program when Push Button is Pushed
http://robotc.net/forums/viewtopic.php?f=11&t=13218
Page 1 of 1

Author:  ChocoTaco [ Fri Jan 22, 2016 3:43 pm ]
Post subject:  Start Program when Push Button is Pushed

I'm trying to make my robot move forwards for a specific amount of time when a button is pushed. The robot is on USB only mode. I want the to 1) turn on the robot and 2)have the robot move forward when the button is pushed. I'm new to this whole gig and I'd really appreciate anyone's help :) Here is the code:

#pragma config(Sensor, dgtl1, sensorTouch, sensorDigitalIn)
#pragma config(Motor, port1, motor1, tmotorVex393_HBridge, openLoop, driveLeft)
#pragma config(Motor, port10, motor2, tmotorVex393_HBridge, openLoop, driveRight)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{

if(SensorValue(sensorTouch) == 1)
{
motor[port1] = 127;
motor[port10] = 127;
wait1Msec(16198);
}
}

Author:  CARBOT [ Sat Jan 23, 2016 6:29 pm ]
Post subject:  Re: Start Program when Push Button is Pushed

What you have would only run if the button was pressed when you started the program.
Lookup the while statement and try this:

Code:
#pragma config(Sensor, dgtl1, sensorTouch, sensorDigitalIn)
#pragma config(Motor, port1, motor1, tmotorVex393_HBridge, openLoop, driveLeft)
#pragma config(Motor, port10, motor2, tmotorVex393_HBridge, openLoop, driveRight)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
  while(1>0)
  {
     if(SensorValue(sensorTouch) == 1)
    {
      motor[port1] = 127;
      motor[port10] = 127;
      wait1Msec(16198);
    }
  }
}

Author:  ChocoTaco [ Mon Jan 25, 2016 1:05 pm ]
Post subject:  Re: Start Program when Push Button is Pushed

CARBOT wrote:
What you have would only run if the button was pressed when you started the program.
Lookup the while statement and try this:

Code:
#pragma config(Sensor, dgtl1, sensorTouch, sensorDigitalIn)
#pragma config(Motor, port1, motor1, tmotorVex393_HBridge, openLoop, driveLeft)
#pragma config(Motor, port10, motor2, tmotorVex393_HBridge, openLoop, driveRight)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
  while(1>0)
  {
     if(SensorValue(sensorTouch) == 1)
    {
      motor[port1] = 127;
      motor[port10] = 127;
      wait1Msec(16198);
    }
  }
}


I tried using that code but I still couldn't get the robot to move :(. I don't know if I'm doing something wrong on my end. I'm using a bumper switch if that matters... Also, since I'm using USB only mode, when I turn the robot on, does that mean that the program is ready to run? Would I have to "clear" the cortex of any possibly existing programs? I really appreciate your help.

Author:  CARBOT [ Tue Jan 26, 2016 12:46 pm ]
Post subject:  Re: Start Program when Push Button is Pushed

Does the robot run if the Cortex is turned on while the USB cable is NOT connected?

Author:  ChocoTaco [ Wed Jan 27, 2016 6:23 pm ]
Post subject:  Re: Start Program when Push Button is Pushed

The robot does not run when the cable is not connected. Nor does it run when the cable is connected. Could this be a firmware issue? Also, there is another person using the robot, so could there be a conflict between my program and theirs?

Author:  CARBOT [ Thu Jan 28, 2016 10:43 pm ]
Post subject:  Re: Start Program when Push Button is Pushed

From RobotC, if you select ROBOT then PLATFORM TYPE, does it have VEX 2.0 Cortex checked?

From RobotC, if you select ROBOT then VEX CORTEX COMMUNICATION MODE, does it have USB ONLY checked?

What happens when you press COMPILE PROGRAM?

What happens when you press DOWNLOAD TO ROBOT?

Author:  CARBOT [ Thu Jan 28, 2016 10:45 pm ]
Post subject:  Re: Start Program when Push Button is Pushed

In USB ONLY mode the robot runs the program when powered up if not connected to a PC.

Author:  ChocoTaco [ Fri Jan 29, 2016 3:48 pm ]
Post subject:  Re: Start Program when Push Button is Pushed

CARBOT wrote:
From RobotC, if you select ROBOT then PLATFORM TYPE, does it have VEX 2.0 Cortex checked?
No, it has VEX IQ checked.
From RobotC, if you select ROBOT then VEX CORTEX COMMUNICATION MODE, does it have USB ONLY checked?
Yes
What happens when you press COMPILE PROGRAM?
It says: "Code generation not performed. Errors during compilation." The error is on 7.020 and it says: **Error**:Typedef enum 'sensorTouch' is already defined.
What happens when you press DOWNLOAD TO ROBOT?

I can not download to robot because of the error in the compiling phase.

Author:  ChocoTaco [ Fri Jan 29, 2016 3:58 pm ]
Post subject:  Re: Start Program when Push Button is Pushed

OK so I tried to compile everything again and there were no errors. However, the robot still does not move. I tried changing the port for the push button but that did not change anything. Here is the code as of now:

#pragma config(Sensor, dgtl12, sensorTouch, sensorTouch)
#pragma config(Motor, port1, motor1, tmotorVex393_HBridge, openLoop, driveLeft)
#pragma config(Motor, port10, motor2, tmotorVex393_HBridge, openLoop, driveRight)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
while(1>0)
{
if(SensorValue(sensorTouch) == 1)
{
motor[port1] = 127;
motor[port10] = 127;
wait1Msec(16198);
}
}
}

Author:  CARBOT [ Sat Jan 30, 2016 6:37 pm ]
Post subject:  Re: Start Program when Push Button is Pushed

Please try this. It worked for me.
Code:
#pragma config(Sensor, dgtl12, sensorTouch, sensorTouch)
#pragma config(Motor, port1, motor1, tmotorVex393_HBridge, openLoop, driveLeft)
#pragma config(Motor, port10, motor2, tmotorVex393_HBridge, openLoop, driveRight)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task main()
{
   while(1>0)
   {
      if(SensorValue[dgtl12] == 1)
      {
         motor[port1] = 40;
         motor[port10] = 40;
         wait1Msec(3000);
         motor[port1] = 0;
         motor[port10] = 0;
      }
   }
}

Author:  ChocoTaco [ Tue Feb 02, 2016 2:22 pm ]
Post subject:  Re: Start Program when Push Button is Pushed

It worked!!! Thank you so much for everything

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/