View unanswered posts | View active topics It is currently Wed Oct 22, 2014 5:46 am






Reply to topic  [ 3 posts ] 
Ports 5-8 not working...Programming problem? 
Author Message
Rookie

Joined: Sun Jul 10, 2011 3:34 pm
Posts: 30
Post Ports 5-8 not working...Programming problem?
Hello,
I have been having some problems with my touch sensors on my VEX PIC robot. On my robot, I currently have eight touch sensors in the "Analog/Digital" ports (ports 1-8). I have noticed that only the sensors in the first four ports (ports 1-4) work. I have taken the sensors from the first four ports, which I know work, and placed them in ports 5-8, then they do not work. I did the same withthe senosrs in ports 5-8, and placed them in 1-4 and they DO work. I then used the sensors debugger window and saw that with all the senors plugged in, the microcontroller knew that they were being pressed. My question is, is there something special I have to do with the program for the ports 5-8 to work? Or is there something worng with my program? Any ideas or help is GREATLY appreciated. Thanks.

p.s. I intentionally commented out and disconnected the Sonar sensor, so I was dealing with ONLY touch sensors.

Here is my code:
#pragma config(Sensor, in1, rearLeft, sensorTouch)
#pragma config(Sensor, in2, rearRight, sensorTouch)
#pragma config(Sensor, in3, rightsideBack, sensorTouch)
#pragma config(Sensor, in4, frontLeft, sensorTouch)
#pragma config(Sensor, in5, frontRight, sensorTouch)
#pragma config(Sensor, in6, rightsideFront, sensorTouch)
#pragma config(Sensor, in7, leftsideFront, sensorTouch)
#pragma config(Sensor, in8, leftsideBack, sensorTouch)
//#pragma config(Sensor, in9, sonarFront, sensorSONAR, int1)
#pragma config(Motor, port1, rightFront, tmotorNormal, openLoop)
#pragma config(Motor, port2, leftRear, tmotorNormal, openLoop)
#pragma config(Motor, port3, leftFront, tmotorNormal, openLoop)
#pragma config(Motor, port4, rightRear, tmotorNormal, openLoop)
#pragma config(Motor, port5, arm, tmotorNormal, openLoop)
#pragma config(Motor, port6, claw, tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

int i;
void forward();
void slightRight1();
void slightRight2();
void slightRight3();
void slightLeft1();
void slightLeft2();
void slightLeft3();
void backupRight();
void backupLeft();
void grabObject();

task main()
{
for(i=0;i<30000;i++)
{
forward();

if(SensorValue(rearLeft) == 1)//1
{
slightRight1();
}//end if

if(SensorValue(rearRight) == 1)//2
{
slightLeft1();
}//end if

if(SensorValue(rightsideBack) == 1)//3
{
slightLeft2();
}//end if

if(SensorValue(frontLeft) == 1)//4
backupRight();
}//end if

if(SensorValue(frontRight) == 1)//5
{
backupLeft();
}//end if

if(SensorValue(rightsideFront) == 1)//6
{
slightLeft3();
}//end if

if(SensorValue(leftsideFront) == 1)//7
{
slightRight2();
}//end if

if(SensorValue(leftsideBack) == 1)//8
{
slightRight3();
}

//if(SensorValue(sonarFront) > 5)
//{
//grabObject();
//}//end if and for

}//end main task



////////////////////////////////////////
void forward()
{
motor[port1] = 40;
motor[port2] = 40;
motor[port3] = 40;
motor[port4] = 40;
wait1Msec(1);
} //end forward
////////////////////////////////////////
void slightRight1()
{
motor[port1] = -40;
motor[port2] = -40;
motor[port3] = 40;
motor[port4] = 40;
wait1Msec(300);
}//end slightRight1
void slightRight2()
{
motor[port1] = -40;
motor[port2] = -40;
motor[port3] = 40;
motor[port4] = 40;
wait1Msec(300);
}//end slightRight2
void slightRight3()
{
motor[port1] = -40;
motor[port2] = -40;
motor[port3] = 40;
motor[port4] = 40;
wait1Msec(300);
}//end slightRight3
/////////////////////////////////////////
void slightLeft1()
{
motor[port1] = 40;
motor[port2] = 40;
motor[port3] = -40;
motor[port4] = -40;
wait1Msec(300);
}//end slightLeft
/////////////////////////////////////////
void slightLeft2()
{
motor[port1] = 40;
motor[port2] = 40;
motor[port3] = -40;
motor[port4] = -40;
wait1Msec(300);
}//end slightLeft2
/////////////////////////////////////////
void slightLeft3()
{
motor[port1] = 40;
motor[port2] = 40;
motor[port3] = -40;
motor[port4] = -40;
wait1Msec(300);
}//end slightLeft3
/////////////////////////////////////////
void backupRight()
{
motor[port1] = -40;
motor[port2] = -40;
motor[port3] = -40;
motor[port4] = -40;
wait1Msec(300);
///////slight back up/////////////

motor[port1] = -40;
motor[port2] = -40;
motor[port3] = 40;
motor[port4] = 40;
wait1Msec(1000);
///////turn right/////////////

}//end backupRight
/////////////////////////////////////////
void backupLeft()
{
motor[port1] = -40;
motor[port2] = -40;
motor[port3] = -40;
motor[port4] = -40;
wait1Msec(300);
///////back up/////////////

motor[port1] = 40;
motor[port2] = 40;
motor[port3] = -40;
motor[port4] = -40;
wait1Msec(1000);
///////turn left/////////////
}//end backupLeft
/////////////////////////////////////////
void grabObject()
{
motor[port1] = 0;
motor[port2] = 0;
motor[port3] = 0;
motor[port4] = 0;
motor[port5] = 0;
motor[port6] = 0;
wait1Msec(1000);//stops for 1 second

motor[port1] = 0;
motor[port2] = 0;
motor[port3] = 0;
motor[port4] = 0;
motor[port5] = -63;
motor[port6] = 0;
wait1Msec(1000); ////arm comes down

motor[port1] = 0;
motor[port2] = 0;
motor[port3] = 0;
motor[port4] = 0;
motor[port5] = 0;
motor[port6] = -10;//arm opens slowly
wait1Msec(1000);

motor[port1] = 0;
motor[port2] = 0;
motor[port3] = 0;
motor[port4] = 0;
motor[port5] = 0;
motor[port6] = 10;//arm closes slowly
wait1Msec(1000);

motor[port1] = 0;
motor[port2] = 0;
motor[port3] = 0;
motor[port4] = 0;
motor[port5] = 63;
motor[port6] = 0;
wait1Msec(2000); ////arm goes back up
}//end grabObject
/////////////////////////////////////////


Mon Sep 05, 2011 12:20 pm
Profile
Site Admin
Site Admin

Joined: Tue May 15, 2007 9:02 am
Posts: 405
Post Re: Ports 5-8 not working...Programming problem?
I tested out all of my ports with touch sensors and they seem to be working. I don't have an identical setup to test your code, but the problem may be that you're turning on and off the same motors in different functions - causing the if statements to "fight" for control and making it seem like they're not working.

One easy way to improve your code may be to incorporate "else{}" branches with the if statements, to prevent different sections from fighting eachother: http://www.education.rec.ri.cmu.edu/pro ... f_else.pdf

_________________
Jesse Flot
CMU Robotics Academy
ROBOTC Support


Tue Sep 06, 2011 8:26 am
Profile
Rookie

Joined: Sun Jul 10, 2011 3:34 pm
Posts: 30
Post Re: Ports 5-8 not working...Programming problem?
Thanks, it works now.


Sun Sep 18, 2011 1:07 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.