View unanswered posts | View active topics It is currently Sat Dec 16, 2017 9:11 am






Reply to topic  [ 11 posts ] 
Start Program when Push Button is Pushed 
Author Message
Rookie

Joined: Thu Jan 21, 2016 3:19 pm
Posts: 6
Post 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);
}
}


Fri Jan 22, 2016 3:43 pm
Profile
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
Post 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);
    }
  }
}


Sat Jan 23, 2016 6:29 pm
Profile
Rookie

Joined: Thu Jan 21, 2016 3:19 pm
Posts: 6
Post 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.


Mon Jan 25, 2016 1:05 pm
Profile
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
Post 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?


Tue Jan 26, 2016 12:46 pm
Profile
Rookie

Joined: Thu Jan 21, 2016 3:19 pm
Posts: 6
Post 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?


Wed Jan 27, 2016 6:23 pm
Profile
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
Post 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?


Thu Jan 28, 2016 10:43 pm
Profile
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
Post 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.


Thu Jan 28, 2016 10:45 pm
Profile
Rookie

Joined: Thu Jan 21, 2016 3:19 pm
Posts: 6
Post 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.


Fri Jan 29, 2016 3:48 pm
Profile
Rookie

Joined: Thu Jan 21, 2016 3:19 pm
Posts: 6
Post 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);
}
}
}


Fri Jan 29, 2016 3:58 pm
Profile
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
Post 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;
      }
   }
}


Sat Jan 30, 2016 6:37 pm
Profile
Rookie

Joined: Thu Jan 21, 2016 3:19 pm
Posts: 6
Post Re: Start Program when Push Button is Pushed
It worked!!! Thank you so much for everything


Tue Feb 02, 2016 2:22 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.