|
longlongago
Rookie
Joined: Wed Apr 25, 2012 8:43 pm Posts: 4
|
 Re: program problem
#pragma config(Sensor, dgtl1, bottom1, sensorTouch) #pragma config(Sensor, dgtl2, bottom2, sensorTouch) #pragma config(Sensor, dgtl3, up1, sensorTouch) #pragma config(Sensor, dgtl4, up2, sensorTouch) #pragma config(Motor, port1, leftup, tmotorVex393, openLoop, reversed) #pragma config(Motor, port2, leftfront, tmotorServoContinuousRotation, openLoop, reversed) #pragma config(Motor, port3, rightfront, tmotorServoContinuousRotation, openLoop) #pragma config(Motor, port4, leftback, tmotorServoContinuousRotation, openLoop, reversed) #pragma config(Motor, port5, rightback, tmotorServoContinuousRotation, openLoop) #pragma config(Motor, port6, leftdown, tmotorVex393, openLoop, reversed) #pragma config(Motor, port7, rightdown, tmotorVex393, openLoop) #pragma config(Motor, port8, leftget, tmotorServoContinuousRotation, openLoop) #pragma config(Motor, port9, rightget, tmotorServoContinuousRotation, openLoop, reversed) #pragma config(Motor, port10, rightup, tmotorVex393, openLoop) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
char tdown=0; char tup=0; task main() { motor[leftget] = 50; motor[rightget] = 50; wait1Msec(200);
while (1==1) //Creates an infinite loop {
motor[leftfront] = vexRT[Ch3] + vexRT[Ch4]; //y-axis value: forward/backward motion motor[leftback] = vexRT[Ch3] + vexRT[Ch4]; motor[rightfront] = vexRT[Ch3] - vexRT[Ch4]; //x-axis value: left/right steering motor[rightback] = vexRT[Ch3] - vexRT[Ch4];
tdown=0; tup=0; if ((SensorValue[up1]+SensorValue[up2])>=1) {tup=1;} else {tup=0;} if ((SensorValue[bottom1]+SensorValue[bottom2])>=1) {tdown=1;} else {tdown=0;}
if (tup+tdown==0) { motor[leftup] = vexRT[Ch2]; motor[rightup] = vexRT[Ch2]; motor[leftdown] = vexRT[Ch2]; motor[rightdown] = vexRT[Ch2]; } else if (tdown==1) { if(vexRT[Ch2]<20) { motor[leftup] = 0; motor[rightup] = 0; motor[leftdown] = 0; motor[rightdown] = 0; } else { motor[leftup] = vexRT[Ch2]; motor[rightup] = vexRT[Ch2]; motor[leftdown] = vexRT[Ch2]; motor[rightdown] = vexRT[Ch2]; } } else if (tup==1) { if(vexRT[Ch2]>-20) { motor[leftup] = 0; motor[rightup] = 0; motor[leftdown] = 0; motor[rightdown] = 0; } else { motor[leftup] = vexRT[Ch2]; motor[rightup] = vexRT[Ch2]; motor[leftdown] = vexRT[Ch2]; motor[rightdown] = vexRT[Ch2]; } }
if(vexRT[Btn6U] == 1) //If button 5U is pressed: { motor[leftget] = 127; //run motor port 5 at quarter speed (i.e. lift an arm) motor[rightget] = 127; } else if(vexRT[Btn6D] == 1) //If button 5D is pressed: { motor[leftget] = -127; //run motor port 5 at quarter speed reversed (i.e. lower an arm) motor[rightget] = -127; } else //If neither buttons 5U or 5D are pressed: { motor[leftget] = 0; motor[rightget] = 0; //stop motor port 5 (i.e. don't move arm up or down) }
}//while }
|
|
longlongago
Rookie
Joined: Wed Apr 25, 2012 8:43 pm Posts: 4
|
 Re: program problem
Before the program runs while() statement,the program can control the motor rightly. when the while() statements begin to execute, maybe some of the four motors(leftup,rightup,leftdown,rightdown)is on immediately and I do not touch the joystick. By the way the motor's direction do not chang.It always lift up the arm. I try to unplug the four motors and restart the cortex and the joystick,another two motor may begin to start. This damaged some green motor protections. Sometimes it just works fine.
|