This would mostly work except for the drive part bc it needs to be in the while loop and it is missing a curly bracket
the thing is I cant use my program until I solve the problem of “function definition not allowed here”
Could you upload a zip file of your code?
wont let a new user send attachments like zip files so here is all of 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)]
// intakeM motor 5
// intakeM2 motor 6
// Lmotor motor 15
// LmotorB motor 16
// Rmotor motor 17
// RmotorB motor 18
// Controller1 controller
// LiftRM motor 14
// LiftLM motor 13
// ---- END VEXCODE CONFIGURED DEVICES ----
#include “vex.h”
using namespace vex;
competition Competition;
void pre_auton(void) {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
}
void autonomous(void) {
}
void usercontrol(void) {
while (1) {
Lmotor.spin(forward, Controller1.Axis2.position(), pct);
Rmotor.spin(forward, Controller1.Axis3.position(), pct);
LmotorB.spin(forward, Controller1.Axis2.position(), pct);
RmotorB.spin(forward, Controller1.Axis3.position(), pct);
vex::motor_group MIntakeM (intakeM, intakeM2);
int armSpeedPCT = 200;
while(true) {
if(Controller1.ButtonUp.pressing())
{
MIntakeM.spin(directionType::fwd, armSpeedPCT, pct);
}
else if(Controller1.ButtonDown.pressing())
{
MIntakeM.spin(directionType::fwd, armSpeedPCT, pct);
}
else
{
MIntakeM.stop();
}
}
}
int main() {
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);
Lmotor.spin(forward, Controller1.Axis2.position(), pct);
Rmotor.spin(forward, Controller1.Axis3.position(), pct);
LmotorB.spin(forward, Controller1.Axis2.position(), pct);
RmotorB.spin(forward, Controller1.Axis3.position(), pct);
int armSpeedPCT = 200;
vex::motor_group MIntakeM (intakeM, intakeM2);
while(true) {
if(Controller1.ButtonUp.pressing())
{
MIntakeM.spin(directionType::fwd, armSpeedPCT, pct);
}
else if(Controller1.ButtonDown.pressing())
{
MIntakeM.spin(directionType::fwd, armSpeedPCT, pct);
}
else
{
MIntakeM.stop();
}
}
pre_auton();
while (true)
{
wait(100, msec);
}
}
}
we got it to work!!!
never mind still not working
You have two while loops inside of each other which is most likely the problem.
void usercontrol(void) {
vex::motor_group MIntakeM (intakeM, intakeM2);
int armSpeedPCT = 200;
while(true) {
Lmotor.spin(forward, Controller1.Axis2.position(), pct);
Rmotor.spin(forward, Controller1.Axis3.position(), pct);
LmotorB.spin(forward, Controller1.Axis2.position(), pct);
RmotorB.spin(forward, Controller1.Axis3.position(), pct);
if(Controller1.ButtonUp.pressing())
{
MIntakeM.spin(directionType::fwd, armSpeedPCT, pct);
}
else if(Controller1.ButtonDown.pressing())
{
MIntakeM.spin(directionType::fwd, armSpeedPCT, pct);
}
else
{
MIntakeM.stop();
}
}
}
//
// 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);
}
}
You have a few major problems. One is that for our usercontrol, you have a while loop on true within another while loop set to true. The second while loop might be messing up everything else and is unneeded so get rid of it. The other issue I see is incorrect defining of the spin function. Right after the first while loop, you illegally defined the parameters in the spin function and that’s where I am getting errors when running your code. Fix these issues and your code should work.
the way i have the spin funtion it works fine but recently i have been getting a error ( [error]: make process closed with exit code : 2 ) any ideas
also at the moment i have gotten ride of all autonomous and started to rewrite my program
my entire code at the moment
/*----------------------------------------------------------------------------*/
/* */
/* 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
// Lmotor motor 15
// LmotorB motor 16
// Rmotor motor 17
// RmotorB motor 18
// intakeRM motor 5
// intakeLM motor 6
// LiftRM motor 14
// LiftLM motor 13
// ---- END VEXCODE CONFIGURED DEVICES ----
#include "vex.h"
using namespace vex;
competition Competition;
void pre_auton(void)
{
vexcodeInit();
}
void autonomous(void)
{
}
void usercontrol(void) {
while (1) {
Lmotor.spin(forward, Controller1.Axis2.position(), pct);
Rmotor.spin(forward, Controller1.Axis3.position(), pct);
LmotorB.spin(forward, Controller1.Axis2.position(), pct);
RmotorB.spin(forward, Controller1.Axis3.position(), pct);
if(Controller1.ButtonA.pressing())
{
intakeLM.setVelocity( 90, percent);
intakeRM.setVelocity( 90, percent);
intakeLM.spin(directionType::fwd);
intakeRM.spin(directionType::rev);
}
else if(Controller1.ButtonB.pressing())
{
intakeLM.setVelocity( 90, percent);
intakeRM.setVelocity( 90, percent);
intakeLM.spin(directionType::rev);
intakeRM.spin(directionType::fwd);
}
else
{
intakeLM.stop(brakeType::hold);
intakeRM.stop(brakeType::hold);
}
wait(20, msec);
}
}
int main() {
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);
pre_auton();
while (true) {
wait(100, msec);
}
}
figured it out you can’t put a space in the title of the program
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.