-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvex drive.iqcpp
98 lines (88 loc) · 3.22 KB
/
vex drive.iqcpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//----------------------------------------------------------------------------
//
// Module: main.cpp
// Author: {author}
// Created: {date}
// Description: IQ project
//
//----------------------------------------------------------------------------
// Include the IQ Library
#include "iq_cpp.h"
// Allows for easier use of the VEX Library
using namespace vex;
float armspeed = 100; //constant float variable
bool driveReversed;
void ToggleDriveDirection()
{
driveReversed = !driveReversed;
}
void SetRiser(bool on, bool up)
{
if(on)
{
if(up)
{
armDrive1.setVelocity(armspeed, percent); //Setvelocity = speed, armDrive and armspeed are floats
armDrive1.spin(forward); //spin forward
armDrive3.setVelocity(armspeed, percent);
armDrive3.spin(forward);
}
else
{
armDrive1.setVelocity(armspeed, percent);
armDrive1.spin(reverse);//spin reverse
armDrive3.setVelocity(armspeed, percent);
armDrive3.spin(reverse);
}
}
else {
armDrive1.setVelocity(1,percent);
armDrive1.spin(forward);
armDrive3.setVelocity(1,percent);
armDrive3.spin(forward);
}
}
void Auton() //Autonomous mode
{
Drivetrain.turnFor(left, 69, degrees); //Setup Drivetrain in Devices menu, then you can do these statements
Drivetrain.driveFor(forward, 420, mm);
SetRiser(true, true); // Turn riser on up
SetRiser(true, true); // Turn riser on down
SetRiser(false, true); // Turn riser off, second bool does not matter when first is false
}
int main() {
Controller.ButtonEUp.pressed(ToggleDriveDirection);
float drivespeed = 100;
int counter = 0;
while(true)
{
leftMotorA.spin(forward, driveReversed ? -Controller.AxisA.position() : Controller.AxisA.position(), percent);//These are for easier reverse of the remote
rightMotorA.spin(forward, driveReversed ? -Controller.AxisD.position() : Controller.AxisD.position(), percent);
leftMotorB.spin(forward, driveReversed ? -Controller.AxisA.position() : Controller.AxisA.position(), percent);
rightMotorB.spin(forward, driveReversed ? -Controller.AxisD.position() : Controller.AxisD.position(), percent);
if (Controller.ButtonRUp.pressing()) //If The Button *x* On Controller is Pressed
{
armDrive1.setVelocity(armspeed, percent);
armDrive1.spin(forward);
armDrive3.setVelocity(armspeed, percent);
armDrive3.spin(forward);
}
else if (Controller.ButtonRDown.pressing()) //Also if the Button *x* On Controller is Pressed
{
{
armDrive1.setVelocity(armspeed, percent);
armDrive1.spin(reverse);
armDrive3.setVelocity(armspeed, percent);
armDrive3.spin(reverse);
}
else //Anything else apart from the if and else if statements
{
armDrive1.setVelocity(1,percent);
armDrive1.spin(forward);
armDrive3.setVelocity(1,percent);
armDrive3.spin(forward);
}
wait(0.1,seconds);
}
wait(0.1,seconds);
}