So I’m trying to program an autonomous but my commands are running separately when I’m trying to run some commands at the same time. Any help would be appreciated. Thanks!
Here is my code
/*----------------------------------------------------------------------------*/
/* */
/* Module: main.cpp */
/* Author: VEX */
/* Created: Thu Sep 26 2019 */
/* Description: Competition Template */
/* */
/*----------------------------------------------------------------------------*/
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// Drivetrain drivetrain 20, 11
// Controller1 controller
// ---- END VEXCODE CONFIGURED DEVICES ----
#include "vex.h"
using namespace vex;
// A global instance of competition
competition Competition;
// defining motors
// define your global instances of motors and other devices here
vex::motor Left(vex::PORT11, vex::gearSetting::ratio18_1,true);
vex::motor Right(vex::PORT20, vex::gearSetting::ratio18_1,false);
vex::motor LeftLift(vex::PORT1, vex::gearSetting::ratio36_1,true);
vex::motor RightLift(vex::PORT10, vex::gearSetting::ratio36_1,false);
vex::motor SecondLift(vex::PORT13, vex::gearSetting::ratio36_1,false);
vex::motor LeftClaw(vex::PORT3, vex::gearSetting::ratio18_1,true);
vex::motor RightClaw(vex::PORT6, vex::gearSetting::ratio18_1,false);
vex::controller con(vex::controllerType::primary);
/*---------------------------------------------------------------------------*/
/* Pre-Autonomous Functions */
/* */
/* You may want to perform some actions before the competition starts. */
/* Do them in the following function. You must return from this function */
/* or the autonomous and usercontrol tasks will not be started. This */
/* function is only called once after the V5 has been powered on and */
/* not every time that the robot is disabled. */
/*---------------------------------------------------------------------------*/
void pre_auton(void) {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, ...
}
/*---------------------------------------------------------------------------*/
/* */
/* Autonomous Task */
/* */
/* This task is used to control your robot during the autonomous phase of */
/* a VEX Competition. */
/* */
/* You must modify the code to add your own robot specific commands here. */
/*---------------------------------------------------------------------------*/
void autonomous(void) {
{
Left.rotateFor(1000,rotationUnits::deg,55,velocityUnits::pct,true);
Right.rotateFor(1000,rotationUnits::deg,55,velocityUnits::pct,true);
}
}
/*---------------------------------------------------------------------------*/
/* */
/* 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 usercontrol(void) {
int LeftLiftSpeedPCT = 90;
int RightLiftSpeedPCT = 90;
int LeftClawSpeedPCT = 100;
int RightClawSpeedPCT = 100;
// User control code here, inside the loop
///Button Y up pri lift
while (1) {
//////////////////////////////////////////////////////////////////////////////////////////////////////
//
//
//
//////////////////////////////////////////////////////////////////////////////////////////////////////
if(con.ButtonUp.pressing()) {
RightLift.spin(directionType::rev, RightClawSpeedPCT, velocityUnits::pct);
}
else if (con.ButtonDown.pressing()) {
RightLift.spin(directionType::fwd, RightClawSpeedPCT, velocityUnits::pct);
}
else{
RightLift.stop(brakeType::brake);
}
if(con.ButtonUp.pressing()) {
LeftLift.spin(directionType::rev, LeftClawSpeedPCT, velocityUnits::pct);
}
else if (con.ButtonDown.pressing()) {
LeftLift.spin(directionType::fwd, LeftClawSpeedPCT, velocityUnits::pct);
}
else{
LeftLift.stop(brakeType::brake);
}
//////////////
if(con.ButtonL1.pressing()) {
SecondLift.spin(directionType::fwd, LeftLiftSpeedPCT, velocityUnits::pct);
}
else if (con.ButtonL2.pressing()) {
SecondLift.spin(directionType::rev, LeftLiftSpeedPCT, velocityUnits::pct);
}
else{
SecondLift.stop(brakeType::brake);
}
if(con.ButtonR1.pressing()) {
RightClaw.spin(directionType::rev, RightClawSpeedPCT, velocityUnits::pct);
}
else if (con.ButtonR2.pressing()) {
RightClaw.spin(directionType::fwd, RightClawSpeedPCT, velocityUnits::pct);
}
else if (con.ButtonY.pressing()) {
RightClaw.spin(directionType::rev, RightClawSpeedPCT, velocityUnits::pct);
}
else if (con.ButtonA.pressing()) {
RightClaw.spin(directionType::fwd, RightClawSpeedPCT, velocityUnits::pct);
}
else{
RightClaw.stop(brakeType::brake);
}
if(con.ButtonR1.pressing()) {
LeftClaw.spin(directionType::rev, LeftClawSpeedPCT, velocityUnits::pct);
}
else if (con.ButtonR2.pressing()) {
LeftClaw.spin(directionType::fwd, LeftClawSpeedPCT, velocityUnits::pct);
}
else if (con.ButtonRight.pressing()) {
LeftClaw.spin(directionType::rev, LeftClawSpeedPCT, velocityUnits::pct);
}
else if (con.ButtonLeft.pressing()) {
LeftClaw.spin(directionType::fwd, LeftClawSpeedPCT, velocityUnits::pct);
}
else{
LeftClaw.stop(brakeType::brake);
}
///
////////
/////////
// 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.
// ........................................................................
wait(20, msec); // Sleep the task for a short amount of time to
// prevent wasted resources.
}
}
//
// Main will set up the competition functions and callbacks.
//
int main() {
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);
// Run the pre-autonomous function.
pre_auton();
// Prevent main from exiting with an infinite loop.
while (true) {
vex::task::sleep(100);
}
}
edit by mods: added code tags