View unanswered posts | View active topics It is currently Sat Oct 25, 2014 5:16 pm






Reply to topic  [ 2 posts ] 
Buttons on the controller not responding 
Author Message
Rookie

Joined: Tue Oct 09, 2012 12:45 pm
Posts: 1
Post Buttons on the controller not responding
So I have a full program that effectively drives the robot, and later on in the program, moves the arm. It uses a potentiometer for position, and takes input from three buttons (7D, 7L, and 7U) to decide what value the motors should approach.
I also added a manual override code to move the arm and disable the automatic moving until it is reactivated.
Even if I try to use code provided on the internet, the arm motors will not move. (port 4, port 5, port 8, and port 9)
The joysticks work totally fine and I've even controlled the arm with the joysticks before.
What's wrong? My potentiometer shows the values below, and we've confirmed that the controller and the motors work.
Code:
#pragma config(Sensor, in2,    ,               sensorPotentiometer)
#pragma config(Sensor, dgtl1,  spatula,        sensorDigitalOut)
#pragma config(Sensor, dgtl2,  descore,        sensorDigitalOut)
#pragma config(Motor,  port2,           frontRight,    tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port3,           backRight,     tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port4,            ,             tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port5,            ,             tmotorVex269, openLoop, reversed)
#pragma config(Motor,  port6,           frontLeft,     tmotorVex393, openLoop)
#pragma config(Motor,  port7,           backLeft,         tmotorVex393, openLoop)
#pragma config(Motor,  port8,            ,             tmotorVex393, openLoop)
#pragma config(Motor,  port9,            ,             tmotorVex269, openLoop)
#pragma platform(VEX)

//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)

#include "Vex_Competition_Includes.c"   //Main competition background code...do not modify!

void pre_auton()
{
  // Set bStopTasksBetweenModes to false if you want to keep user created tasks running between
  // Autonomous and Tele-Op modes. You will need to manage all user created tasks if set to false.
  bStopTasksBetweenModes = true;

   // All activities that occur before the competition starts
   // Example: clearing encoders, setting servo positions, ...
}

/////////////////////////////////////////////////////////////////////////////////////////
//
//                                 Autonomous Task
//
// This task is used to control your robot during the autonomous phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//
/////////////////////////////////////////////////////////////////////////////////////////

task autonomous()
{
  // .....................................................................................
  // Insert user code here.
  // .....................................................................................

   AutonomousCodePlaceholderForTesting();  // Remove this function call once you have "real" code.
}

/////////////////////////////////////////////////////////////////////////////////////////
//
//                                 User Control Task
//
// This task is used to control your robot during the user control phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//
/////////////////////////////////////////////////////////////////////////////////////////

task usercontrol()
{
   // User control code here, inside the loop

   while (true)
   {
     int X2 = 0, Y1 = 0, X1 = 0, threshold = 5;
   bool spatulafired = false;
   int desiredvalue = 3045;
   bool manual = true;
   while(1 == 1)
   {

      //Create "deadzone" for Y1/Ch3
      if(abs(vexRT[Ch3]) > threshold)
         if (abs(vexRT[Ch3]) < 110){
         Y1 = (vexRT[Ch3]/2);
         } else {
         Y1 = vexRT[Ch3];
      }
      else
         Y1 = 0;
      //Create "deadzone" for X1/Ch4
      if(abs(vexRT[Ch4]) > threshold)
         if (abs(vexRT[Ch4]) < 110){
         X1 = (vexRT[Ch4]/2);
         } else {
         X1 = vexRT[Ch4];
      }
      else
         X1 = 0;
      //Create "deadzone" for X2/Ch1
      if(abs(vexRT[Ch1]) > threshold)
         if (abs(vexRT[Ch1]) < 110){
         X2 = (vexRT[Ch1]/2);
         } else {
         X2 = vexRT[Ch1];
      }
      else
         X2 = 0;

      //Perform calculations and set motors accordingly.
      motor[frontRight] = Y1 - X2 - X1;
      motor[backRight] =  Y1 - X2 + X1;
      motor[frontLeft] = Y1 + X2 + X1;
      motor[backLeft] =  Y1 + X2 - X1;
   }
   //Controls for spatula pneumatics.
   if(vexRT[Btn8D] == 1){
      if(spatulafired == true){
         spatulafired = false;
         } else {
         spatulafired = true;
      }
   }
   if(spatulafired == true){
      SensorValue[spatula] = 1;
      }else{
      SensorValue[spatula] = 0;
   }
   
   if(vexRT[Btn6U] == 1){
      manual = true;
      motor[port4] = 90;
      motor[port5] = 90;
      motor[port8] = 90;
      motor[port9] = 90;
   } else if(vexRT[Btn6D] == 1){
      manual = true;
      motor[port4] = -90;
      motor[port5] = -90;
      motor[port8] = -90;
      motor[port9] = -90;
   } else {
      if(manual == true){
         motor[port4] = 0;
         motor[port5] = 0;
         motor[port8] = 0;
         motor[port9] = 0;
      }
   }
   
   if (vexRT[Btn7D] == 1){
      manual = false;
      desiredvalue = 3045;
   }else if(vexRT[Btn7L] == 1){
      manual = false;
      desiredvalue = 2504;
   }else if(vexRT[Btn7U] == 1){
      manual = false;
      desiredvalue = 1828;
   }
   
   if (manual == false){
      if(abs(SensorValue[in2] - desiredvalue) > 15){
         if (SensorValue[in2] > desiredvalue){
            motor[port4] = 127;
            motor[port5] = 127;
            motor[port8] = 127;
            motor[port9] = 127;
         } else {
            motor[port4] = -127;
            motor[port5] = -127;
            motor[port8] = -127;
            motor[port9] = -127;
         }
      } else if(abs(SensorValue[in2] - desiredvalue) <= 15 && abs(SensorValue[in2] - desiredvalue) > 2){
         if (SensorValue[in2] > desiredvalue){
            motor[port4] = 63;
            motor[port5] = 63;
            motor[port8] = 63;
            motor[port9] = 63;
         } else {
            motor[port4] = -63;
            motor[port5] = -63;
            motor[port8] = -63;
            motor[port9] = -63;
         }
      } else {
         motor[port4] = 0;
         motor[port5] = 0;
         motor[port8] = 0;
         motor[port9] = 0;
      }
   }
   }
}


Tue Oct 09, 2012 12:52 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 596
Post Re: Buttons on the controller not responding
It appears that your second infinite loop ( while (1==1) ) is being closed early by the brace after the motor power assignments:

Code:
 motor[frontRight] = Y1 - X2 - X1;
      motor[backRight] =  Y1 - X2 + X1;
      motor[frontLeft] = Y1 + X2 + X1;
      motor[backLeft] =  Y1 + X2 - X1;
   **}**


I would suggest making sure the braces line up when coding (it makes it a lot easier to read and debug) and to utilize the powerful debugging tools ROBOTC offers (such as stepping through a program with the Debug Window and highlighting program execution), especially for a more complex program such as this. It can help make debugging errors a lot easier and quicker.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Thu Oct 11, 2012 5:14 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 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.