View unanswered posts | View active topics It is currently Tue May 21, 2019 3:03 am






Reply to topic  [ 2 posts ] 
Jerkyness when multitasking 
Author Message
Rookie

Joined: Tue May 05, 2015 4:18 pm
Posts: 2
Post Jerkyness when multitasking
I've been trying to control the motors that are drive a robot in one task and the sequence for triggering some solenoids in another but the multitasking has made the wheel motors all jumpy.

Also as a interesting note, when I watch the motor debugging window it tends to favor powering the front motors and is only really jumpy when going straight forwards

Any ideas on how to correct that without making the robot stop every times I trigger the solenoids?




Code:
#pragma config(Motor,  port2,           FL,            tmotorServoContinuousRotation, openLoop, driveLeft)
#pragma config(Motor,  port3,           FR,            tmotorServoContinuousRotation, openLoop, driveRight)
#pragma config(Motor,  port4,           BL,            tmotorServoContinuousRotation, openLoop, driveLeft)
#pragma config(Motor,  port5,           BR,            tmotorServoContinuousRotation, openLoop, driveRight)
#pragma config(Motor,  port6,           valve1R,       tmotorServoStandard, openLoop)
#pragma config(Motor,  port7,           valve1F,       tmotorServoStandard, openLoop)
#pragma config(Motor,  port8,           valve2R,       tmotorServoStandard, openLoop)
#pragma config(Motor,  port9,           valve2F,       tmotorServoStandard, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

int drivecurve_Y(int y) //define throttle curve front-back
{
   //first try: 100(0.853x/100)^3 (throttle curve equation)
   // second try: (109*(.853x/100)^2)*(abs(x)/x) -- reduce power to 2, re-salt to get 127,127 crossing, preserve sign/direction
   int output_Y;
   output_Y = round((109*(pow(((0.853*(y))/100),2)*(abs(y))/(y+0.1))));
   return output_Y;
}
int drivecurve_X(int x) //define throttle curve front-back
{
   //first try: 100(0.853x/100)^3 (throttle curve equation)
   // second try: (109*(.853x/100)^2)*(abs(x)/x) -- reduce power to 2, re-salt to get 127,127 crossing, preserve sign/direction
   int output_X;
   output_X = round((109*(pow(((0.853*(x))/100),2)*(abs(x))/(x+0.1))));
   return output_X;
}


task firecontrol()
{

  while(1 == 1)
  {
    if(vexRT[Btn7L]==1)
    {
      motor[valve1F] = 127;
      motor[valve2F] = 127;

      wait1Msec(500);

      motor[valve1F] = 0;
      motor[valve2F] = 0;
      wait1Msec(5);
      motor[valve1R] = 127;
         motor[valve2R] = 127;
      wait1Msec(500);

      motor[valve1R] =  0;
         motor[valve2R] = 0;
      // wait until the button is no longer pressed
      while (vexRT[Btn7L]==1)
        sleep(10);
    }
  }
}

task arcadedrive(){

int deadband = 10;


while(1 == 1)

{

if(vexRT[Btn7D]==0 && abs(vexRT[Ch2]) >= deadband || abs(vexRT[Ch1])>= deadband)
   {
      bMotorReflected[FR] = true;

      motor[FL] = drivecurve_Y(vexRT[Ch2]) + drivecurve_X(vexRT[Ch1]);
      motor[FR] = drivecurve_Y(vexRT[Ch2]) - drivecurve_X(vexRT[Ch1]);
      motor[BL] = drivecurve_Y(vexRT[Ch2]) + drivecurve_X(vexRT[Ch1]);
      motor[BR] = drivecurve_Y(vexRT[Ch2]) - drivecurve_X(vexRT[Ch1]);
   }

if(vexRT[Btn7D]==1 && abs(vexRT[Ch2]) >= deadband || abs(vexRT[Ch1])>= deadband)
   {
      bMotorReflected[FL] = true;
      bMotorReflected[BL] = true;
      bMotorReflected[BR] = true;
      motor[FL] = drivecurve_Y(vexRT[Ch2]) + drivecurve_X(vexRT[Ch1]);
      motor[FR] = drivecurve_Y(vexRT[Ch2]) - drivecurve_X(vexRT[Ch1]);
      motor[BL] = drivecurve_Y(vexRT[Ch2]) + drivecurve_X(vexRT[Ch1]);
      motor[BR] = drivecurve_Y(vexRT[Ch2]) - drivecurve_X(vexRT[Ch1]);
   }

   else{
      motor[FL] = 0;
      motor[FR] = 0;
      motor[BL] = 0;
      motor[BR] = 0;
   }

}
}

task main(){

startTask(firecontrol);
startTask(arcadedrive);

while(true){
   wait1Msec(100);
}
}



Mon May 11, 2015 2:45 am
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 722
Post Re: Jerkyness when multitasking
Code:
if(vexRT[Btn7D]==0 && abs(vexRT[Ch2]) >= deadband || abs(vexRT[Ch1])>= deadband)
   {
//Drive motors
   }

if(vexRT[Btn7D]==1 && abs(vexRT[Ch2]) >= deadband || abs(vexRT[Ch1])>= deadband)
   {
//Drive motors
   }

   else{
//Stop motors
   }


My guess is that the issue you are running into is in the code above. If the first 'if' statement's condition is true, the motors get turned on, but then the code immediately checks the second 'if' statement and, if it is false, turns the motors back off. This is what is most likely causing the shaking that you are experiencing.

To solve this, simply change the second 'if' statement to an 'else if' statement; that way only one of the three drive control codes will execute on each pass of the loop.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our updated help documentation and the ROBOTC Forums.


Mon May 11, 2015 9:22 am
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.