View unanswered posts | View active topics It is currently Thu Apr 17, 2014 2:28 pm






Reply to topic  [ 8 posts ] 
program problem 
Author Message
Rookie

Joined: Wed Apr 25, 2012 8:43 pm
Posts: 4
Post program problem
Sometime some motor is suddenly on and the robot is out of control when the cortex is startting to run the joystick control program.
This situation did not always happen.
I use the version of 3.08.
I changed a new controller,the same thing happened again.
When I use easyc everything is ok.


Wed Apr 25, 2012 8:58 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: program problem
Can you post your code so we can see if that is the source of the problem?

_________________
sudo rm -rf /


Wed Apr 25, 2012 9:20 pm
Profile
Rookie

Joined: Wed Apr 25, 2012 8:43 pm
Posts: 4
Post 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
}


Wed Apr 25, 2012 9:52 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: program problem
Can you describe precisely what problem you're having? What do you expect to happen, and what actually happens? Which motors are running out of control? When does this happen?

_________________
sudo rm -rf /


Wed Apr 25, 2012 10:49 pm
Profile
Rookie

Joined: Wed Apr 25, 2012 8:43 pm
Posts: 4
Post 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.


Thu Apr 26, 2012 4:07 am
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: program problem
Next time you post some code, please place it in
Code:
[code][/code]
tags to preserve indentation and make it easier to read. Otherwise, it makes it difficult to see which curly braces affect what. I've done it for you here, and maybe you or a mod can come and fix it for you up there:
Code:
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
}

_________________
sudo rm -rf /


Thu Apr 26, 2012 1:51 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: program problem
It's a little hard to follow your code, as it's a little redundant. If you keep writing the same thing (setting all motors to ch2, or zero in your case), there's a good chance that there is a better way to do it. Take a look at this code, and tell me if it does what you want it to do. If so, try it out and see if it still produces the same problems. (I'm not responsible if this code damages your robot):
Code:
task main()
{
  motor[leftget] = 50;
  motor[rightget] = 50;
  wait1Msec(200);

  bool tup = false;
  bool tdown = false;

// !!! I changed tup and tdown to booleans, as there's no reason to have them as chars !!! //

  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=false;
    tup=false;
    if (SensorValue[up1] || SensorValue[up2]) {tup=true;}
    if (SensorValue[bottom1] || SensorValue[bottom2]) {tdown=true;}
   
    if((!(tdown || tup)) || (tdown && vexRT[Ch2] >= 20) || (tup && vexRT[Ch2] <= -20))
    {
      motor[leftup] = vexRT[Ch2];
      motor[rightup] = vexRT[Ch2];
      motor[leftdown] = vexRT[Ch2];
      motor[rightdown] = vexRT[Ch2];
    }
    else
    {
      motor[leftup] = 0;
      motor[rightup] = 0;
      motor[leftdown] = 0;
      motor[rightdown] = 0;
    }

    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
}

_________________
sudo rm -rf /


Thu Apr 26, 2012 2:07 pm
Profile
Rookie

Joined: Wed Apr 25, 2012 8:43 pm
Posts: 4
Post Re: program problem
Thank you !
let me make more tests.


Tue May 01, 2012 8:16 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 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.