View unanswered posts | View active topics It is currently Mon Oct 21, 2019 6:32 pm






Reply to topic  [ 2 posts ] 
DOUBLE FLYWHEEL HELP WITH CODE 
Author Message
Rookie

Joined: Sun Jan 10, 2016 12:25 am
Posts: 1
Post DOUBLE FLYWHEEL HELP WITH CODE
Hi I have 2 motors with IME's that I havent been able to make work. The following code is both my autonomous and my Driver Control. I have not been able to make autonomous work but I dont know whats wrong. Also for Driver Control only my intake mechanism and my drive work. I cant get flywheels to spin in driver control and i cant get anything to work in autonomous to work at all. please help in any way you can.


Code:
#pragma platform(VEX)
#pragma config(motor,  port1,        tmotorVex393_HBridge, openLoop)// Front Left      || 1    ||
#pragma config(motor,  port2,        tmotorVex393_MC29,    openLoop)// Back Left       || 2    ||
#pragma config(motor,  port3,        tmotorVex393_MC29,    openLoop)// Back Right      || 3    ||
#pragma config(motor,  port4,        tmotorVex393_MC29,    openLoop, encoderPort, I2C_1)// Left Launchers  || 4 Y  ||
#pragma config(motor,  port5,        tmotorVex393_MC29,    openLoop, reversed, encoderPort, I2C_2)// Right Launchers || 5 Y  ||
#pragma config(motor,  port6,        tmotorVex393_MC29,    openLoop)// Lift Motor Left || 6    ||
#pragma config(motor,  port7,        tmotorVex393_MC29,    openLoop)// Lift Moror Right|| 7    ||
#pragma config(motor,  port8,        tmotorVex393_MC29,    openLoop)// Intake Motor    || 8    ||
#pragma config(motor,  port9,        tmotorVex393_MC29,    openLoop)// Conveyer Belt   || 9    ||
#pragma config(motor,  port10,       tmotorVex393_HBridge, openLoop)// Front Right     || 10   ||
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, I2C_1,  LLE,            sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Sensor, I2C_2,  RLE,            sensorQuadEncoderOnI2CPort,    , AutoAssign)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

//////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                       VEX Competition Control Include File
//
// This file provides control over a VEX Competition Match. It should be included in the user's
// program with the following line located near the start of the user's program
//        #include "VEX_Competition_Includes.h"
// The above statement will cause this program to be included in the user's program. There's no
// need to modify this program.
//
// The program displays status information on the new VEX LCD about the competition state. You don't
// need the LCD, the program will work fine whether or not the LCD is actually provisioned.
//
// The status information is still useful without the LCD. The ROBOTC IDE debugger has a "remote screen"
// that contains a copy of the status information on the LCD. YOu can use this to get a view of the
// status of your program. The remote screen is shown with the menu command
//   "Robot -> Debugger Windows -> VEX Remote Screen"
//
// The LCD is 2 lines x 16 characters. There are three display formats to look for:
//
//        State          Description
//
//    ----------------
//   |Disabled        |  The robot is idle. This occurs before both the autonomous and user
//   |Time mm:ss.s    |  control states. The time display is minutes and seconds it has been idle.
//    ----------------
//
//    ----------------
//   |Autonomous      |  The robot is running autonomous code.
//   |Time mm:ss.s    |  control states. The time display is minutes and seconds it has been running.
//    ----------------
//
//    ----------------
//   |User Control    |  The robot is running user control code.
//   |Time mm:ss.s    |  control states. The time display is minutes and seconds it has been running.
//    ----------------
//////////////////////////////////////////////////////////////////////////////////////////////////////


void allMotorsOff();
void allTasksStop();


//#pragma config(Motor,  port4,           ll,            tmotorVex393_MC29, openLoop, encoderPort, I2C_1)
//#pragma config(Motor,  port5,           rl,            tmotorVex393_MC29, openLoop, reversed, encoderPort, I2C_2)

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


/////////////////////////////////////////////////////////////////////////////////////////
//
//                          Pre-Autonomous Functions
//
// You may want to perform some actions before the competition starts. Do them in the
// following function.
//
/////////////////////////////////////////////////////////////////////////////////////////

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.

   // All activities that occur before the competition starts
   // Example: clearing encoders, setting servo positions, ...
}
#define m motor
#define sv SensorValue
#define rt vexRT
#define w wait


void intake(int speed)
{
   m[port9]= speed;
   m[port8] = speed;
}
void shoot(int speed)
{
  m[port4]= -speed;
   m[port5]=  speed;
}

void rotateleft(int speed)
{
   m[port10] = speed;
   m[port1] = speed;
   m[port3] = speed;
   m[port2] = speed;
}

void rotateleft(int speed)
{
   m[port10] = -speed;
   m[port1] = -speed;
   m[port3] = -speed;
   m[port2] = -speed;
}

void advance(int speed)
{
   m[port10] = -speed;
   m[port1] = speed;
   m[port3] = -speed;
   m[port2] = speed;
}

void strafeleft(int speed)
{
   m[port10] = -speed;
   m[port1] = -speed;
   m[port3] = speed;
   m[port2] = speed;
}

void straferight(int speed)
{
   m[port10] = speed;
   m[port1] = speed;
   m[port3] = -speed;
   m[port2] = -speed;
}

void diagonalleft(int speed)
{
   m[port10] = -speed;
   m[port2] = speed;
}

void diagonalright(int speed)
{
   m[port1] = -speed;
   m[port3] = speed;
}

task autonomous()
{
   
   w(50);
  shoot(124);
   w(5000);               //cooling period for launcher to reach full speed
   intake(100);
   w(200000);              //ball 1 launched
   intake(0);            //intake stops
   w(50000);               //cooling period for launcher to reach full speed
   intake(100);
   w(2000);              //ball 2 launched
   intake(0);            //intake stops
   w(500);               //cooling period for launcher to reach full speed
   intake(100);
   w(2000);              //ball 3 launched
   intake(0);            //intake stops
   w(500);               //cooling period for launcher to reach full speed
   intake(100);
   w(2000);              //ball 1 launched           //intake continues as robot trys to pick up balls
   shoot(0);
   advance(127);     // full speed ahead
   w(1000);
   strafeleft(127);  //strafe left
   w(1000);
   straferight(127); //strafe right
   w(1000);
   advance(-127);    //full speed back
   w(1000);
   advance(0);        //all motors stop

   // .....................................................................................
   // Insert user code here.
   // .....................................................................................

}

/////////////////////////////////////////////////////////////////////////////////////////
//
//                                 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.
//
/////////////////////////////////////////////////////////////////////////////////////////
void launcherspeed(int speed)
{
   m[port4]= -speed;
   m[port5]= speed;
}
task usercontrol()
{
   // User control code here, inside the loop

   while (true)
   {
      //MAIN CONTROLLER
      //MOVEMENT:STRAFE   FORWARD   ROTATION
      m[port1] =   rt[Ch4] + rt[Ch3] + rt[Ch1];
      m[port2] =  -rt[Ch4] + rt[Ch3] + rt[Ch1];
      m[port3] =  -rt[Ch4] - rt[Ch3] + rt[Ch1];
      m[port10]=   rt[Ch4] - rt[Ch3] + rt[Ch1];

      //left Launchers
      if (rt[btn8D]>0)
      {
         nMotorEncoder[port4]=0;
         nMotorEncoder[port5]=0;   
         launcherspeed(31);
      }

      if (rt[btn8L]>0)
      {
         nMotorEncoder[port4]=0;
         nMotorEncoder[port5]=0;   
         launcherspeed(62);
      }      

      if (rt[btn8U]>0)
      {
         nMotorEncoder[port4]=0;
         nMotorEncoder[port5]=0;
         launcherspeed(93);
      }      

      if (rt[Btn8R]>0)
      {
         nMotorEncoder[port4]=0;
         nMotorEncoder[port5]=0;   
         launcherspeed(124);
      }
      
      //Conveyer belt
      m[port9] = (rt[Btn5U]-rt[Btn5D])*127;
      //intake motor (inverted for inuitiveness)
      m[port8] = (rt[Btn5U]-rt[Btn5D])*127;

      //The following is the lift
      m[port6] = (rt[Btn6UXmtr2]-rt[Btn6DXmtr2])*127;

      m[port7] = -m[port6];

      // This is the main execution loop for the user control program. Each time through the loop
      // your program should update motor + servo values based on feedback from the joysticks.

      // .....................................................................................
      // Insert user code here. This is where you use the joystick values to update your motors, etc.
      // .....................................................................................

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


Sun Jan 10, 2016 12:50 am
Profile
Moderator
Moderator

Joined: Tue May 19, 2015 3:07 pm
Posts: 91
Post Re: DOUBLE FLYWHEEL HELP WITH CODE
Okay so for starters is there a specific reason you use precompiler commands to hide what functions you are calling. I think you had physically typed the word wait every time you needed it the dropdown suggestion menu would have shown you that you were using the wrong command. If you right click wait and then click "go to definition" you will see

void wait(const float quantity = 1.0, const tMovementUnits unitType = seconds)

Which means that unless specified assume units are in seconds. This means your autonomous sits and waits for 50 seconds before allowing anything else to run. I would suggest any of the following
Code:
sleep(50);
delay(50);
wait1Msec(50);

All of which sleep for units in milliseconds.

In driver control it appears you set the motor power for the flywheel incredibly quickly. You set the power to 0 and instantly set it to not zero. And you allow the motors on the flywheel to be controlled by more than button at a time. This means in the process of 1 millisecond the worst case scenario is the motors are given 8 commands, half of which are to turn the motors off. I cleaned this up to ensure the motors are not updated needlessly.

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

   while (true)
   {
      //MAIN CONTROLLER
      //MOVEMENT:STRAFE   FORWARD   ROTATION
      m[port1] =   rt[Ch4] + rt[Ch3] + rt[Ch1];
      m[port2] =  -rt[Ch4] + rt[Ch3] + rt[Ch1];
      m[port3] =  -rt[Ch4] - rt[Ch3] + rt[Ch1];
      m[port10]=   rt[Ch4] - rt[Ch3] + rt[Ch1];

      //left Launchers
      if (rt[btn8D])
      {
         launcherspeed(31);
      }else if (rt[btn8L])
      {
         launcherspeed(62);
      }else  if (rt[btn8U])
      {
         launcherspeed(93);
      }else if (rt[Btn8R])
      {
         launcherspeed(124);
      }

      //Conveyer belt
      m[port9] = (rt[Btn5U]-rt[Btn5D])*127;
      //intake motor (inverted for inuitiveness)
      m[port8] = (rt[Btn5U]-rt[Btn5D])*127;

      //The following is the lift
      m[port6] = (rt[Btn6UXmtr2]-rt[Btn6DXmtr2])*127;

      m[port7] = -m[port6];

      // This is the main execution loop for the user control program. Each time through the loop
      // your program should update motor + servo values based on feedback from the joysticks.

      sleep(50);//Don't hog CPU
   }
}


Wed Jan 13, 2016 4:06 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.