Pneumatic System doesnt work with drivetrain

Hey everyone,


I am having a problem with our pneumatic system and the drivetrain.
We created a programm where we can drive (and it should do the pneumatics stuff too, but it doesn´t) but when we made the exact same code without the drivetrain it worked.
I was wondering if there is anybody who can help us?

If you need this, here´s the code:

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       VEX                                                       */
/*    Created:      Thu Sep 26 2019                                           */
/*    Description:  Competition Template                                      */
/*                                                                            */
/*----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Controller1          controller                    
// LFDrive              motor         6               
// LBDrive              motor         9               
// RFDrive              motor         14              
// RBDrive              motor         17              
// DigitalOutG          digital_out   G               
// DigitalOutH          digital_out   H               
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"


using namespace vex;

// A global instance of competition
competition Competition;

// define your global instances of motors and other devices here

/*---------------------------------------------------------------------------*/
/*                          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.                               */
/*---------------------------------------------------------------------------*/
bool pneu = false;
bool shooting = false;
bool pneushoot = false;


void init() {
  DigitalOutG.set(false);
  DigitalOutH.set(false);
}

void turnleft() {
  RBDrive.spinFor(forward, 1, turns);
  RFDrive.spinFor(forward, 1, turns);
  LBDrive.spinFor(reverse, 1, turns);
  LFDrive.spinFor(reverse, 1, turns);
}

void forwarddrive() {
  RBDrive.spinFor(forward, 1, turns);
  RFDrive.spinFor(forward, 1, turns);
  LBDrive.spinFor(forward, 1, turns);
  LFDrive.spinFor(forward, 1, turns);
}

void axisthreechanged() {
  LFDrive.spin(forward, Controller1.Axis3.value() * 0.5, pct);
  LBDrive.spin(forward, Controller1.Axis3.value() * 0.5, pct);
  RFDrive.spin(reverse, Controller1.Axis3.value() * 0.5, pct);
  RBDrive.spin(reverse, Controller1.Axis3.value() * 0.5, pct);
}

void axisfourchanged() {
  LFDrive.spin(reverse, Controller1.Axis1.value() * 0.5, pct);
  LBDrive.spin(reverse, Controller1.Axis1.value() * 0.5, pct);
  RFDrive.spin(reverse, Controller1.Axis1.value() * 0.5, pct);
  RBDrive.spin(reverse, Controller1.Axis1.value() * 0.5, pct);
}
void solenoid() {
  if (!pneu) {
    DigitalOutG.set(true);
    DigitalOutH.set(true);
    pneu = true;
  } else if (pneu) {
    DigitalOutG.set(false);
    DigitalOutH.set(false);
    pneu = false;
  }
}

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) {
  // ..........................................................................
  // Insert autonomous 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 usercontrol(void) {
  // User control code here, inside the loop
  while (1) {
    // 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.
    init();
    // ........................................................................
    // Insert user code here. This is where you use the joystick values to
    // update your motors, etc.
    // ........................................................................
    Controller1.Axis1.changed(axisfourchanged);
    Controller1.Axis3.changed(axisthreechanged);
    Controller1.ButtonL1.pressed(solenoid);
    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() {
  // Set up callbacks for autonomous and driver control periods.
  Competition.autonomous(autonomous);
  Competition.drivercontrol(usercontrol);

  // Run the pre-autonomous function.
  pre_auton();

  // Prevent main from exiting with an infinite loop.
  while (true) {
    wait(100, msec);
  }
}

Thanks for help!

Do not register event handlers multiple times. In general most teams just drive the motors with the joystick power inside of the while true loop and I do not advise using the on changed event handler for this.

Also, your init is being called constantly, resulting in the pistons constantly being set to false.

1 Like