View unanswered posts | View active topics It is currently Sat Oct 25, 2014 10:34 am






Reply to topic  [ 3 posts ] 
bumper switch NOT responding with more than one command 
Author Message
Rookie

Joined: Sun Jul 10, 2011 3:34 pm
Posts: 30
Post bumper switch NOT responding with more than one command
I cannot get my PIC VEX robot to run more than one command at a time and have the bumper switch stop it at any given time. When I only give it one command and use the bumper switch, and the bumper switch is activated, it will stop, but not with more than one command. I have tried almost all of the if statements and control structures and cannot get it to work correctly. Is there something wrong with my coding? Should I be doing something different? In the end I wanted my robot to drive a certain route, and if the bumper switch is hit (the robot runs into something), then the robot would stop.
Thanks to anyone who can help.

Here is my code below:

Code:
#pragma config(Sensor, in1,    touchSensor,         sensorTouch)
#pragma config(Motor,  port1,           motor1,        tmotorNormal, openLoop)
#pragma config(Motor,  port2,           motor2,        tmotorNormal, openLoop)
#pragma config(Motor,  port3,           motor3,        tmotorNormal, openLoop)
#pragma config(Motor,  port4,           motor4,        tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

void bump();         //Function declaration for bump
void move(int portOne,int portTwo,int portThree,int portFour,int waitTime); //Function declaration for move, which takes three integer parameters
task main()
{
  wait1Msec(2000);                  //Robot waits for 2000 milliseconds before executing program

    while(1 == 1) //Creates an infinite loop
    {

      //code to move robot forward here

motor[port1] = -63; //run at half power
motor[port2] = -63;
motor[port3] = 63;
motor[port4] = 63;
wait1Msec(2800);

motor[port1] = 0; //stops
motor[port2] = 0;
motor[port3] = 0;
motor[port4] = 0;
wait1Msec(2000);


motor[port1] = 63; //right turn
motor[port2] = 63;
motor[port3] = 63;
motor[port4] = 63;
wait1Msec(650);

motor[port1] = 0; //stops
motor[port2] = 0;
motor[port3] = 0;
motor[port4] = 0;
wait1Msec(2000);


//Robot movement stops, unless bumper swtich interupts

      if(SensorValue(touchSensor) == 0)
      {
        bump();   //Call and run the bump function

      }//end if

    }//end while



}//end main

void bump()      //Function definition for bump
{
   if(SensorValue[touchSensor] == 1)   //If bumper is pressed
   {
      move(0, 0, 0, 0, 3000);   //Call and run the move function, with portThree = -63, portTwo = -63, waitTime = 500
      move(0, 0, 0, 0, 6000);   //Call and run the move function, with portThree = 63, portTwo = -63, waitTime = 1000
   }
}


void move(int portOne,int portTwo,int portThree,int portFour,int waitTime)      //Function definition for move
{
   motor[port1] = portOne;
   motor[port2] = portTwo;
   motor[port3] = portThree;
   motor[port4] = portFour;
   wait1Msec(waitTime);            //Waits the number of milliseconds specified in the waitTime parameter
}


Fri Aug 05, 2011 1:12 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: bumper switch NOT responding with more than one command
I don't really understand what you want your program to do. Do you want the robot to execute the set of movements specified, and stop anytime that the button is pressed? If so, I would recommend multitasking. Here is how you would do it:

Code:
task bumpPress(){
  if(SensorValue[bump] == 1){
    hogCPU();
    //whatever you want the robot to do when the switch is pressed
    //If you want to stop the program, add StopAllTasks();
    //If you Don't want to resume the main task when the bumper is released, you will need
    //to insert a boolean flag or something
  }
}

task main(){
  StartTask(bumpPress);
    while(true){
      motor[port1] = -63; //run at half power
      motor[port2] = -63;
      motor[port3] = 63;
      motor[port4] = 63;
      wait1Msec(2800);

      motor[port1] = 0; //stops
      motor[port2] = 0;
      motor[port3] = 0;
      motor[port4] = 0;
      wait1Msec(2000);

      motor[port1] = 63; //right turn
      motor[port2] = 63;
      motor[port3] = 63;
      motor[port4] = 63;
      wait1Msec(650);

      motor[port1] = 0; //stops
      motor[port2] = 0;
      motor[port3] = 0;
      motor[port4] = 0;
      wait1Msec(2000);
  }
}

_________________
sudo rm -rf /


Fri Aug 05, 2011 4:54 pm
Profile
Rookie

Joined: Sun Jul 10, 2011 3:34 pm
Posts: 30
Post Re: bumper switch NOT responding with more than one command
Thanks for your help. That's what I wanted to do.


Sat Aug 06, 2011 6:59 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.