I am currently writing out a code for a 3rd party competition, it is a full autonomous game therefore i need multiple sensors to map out a route and if the robot surpasses a limit it will back up and avoid that section to its best ability. However i am having some issues trying to find a command that can “disable” other distance sensors while a sensor is detecting a object that is closer than all other sensor or is that a non-existent command.
Btw the claws don’t serve a purpose yet, they are there as a placeholder for when we plan to use them
Ports:
Drivetrain - Port 7, 1
Claw1 - Claw #1 - Port 2
Claw2 - Claw #2 - Port 3
Distance1_DSR - Distance #1 Down Side Right - Port 4
Distance2_DSL - Distance #2 Down Side Left - Port 5
Distance3_DF - Distance #3 Down Front - Port 6
Distance4_DR - Distance #4 Down Rear - Port 8
Distance5_OSR - Distance #5 Outwards Side Right - Port 9
Distance6_OSL - Distance #6 Outwards Side Left - Port 10
Distance7_OF - Distance #7 Outwards Front - Port 11
Distance8_OR - Distance #8 Outwards Rear - Port 12
Code:
[Comp C1 B1.iqblocks|attachment](upload://qRylFMpXZBOQxJBvaH1Y4GwC1rT.iqblocks) (23.4 KwB)
float myVariable, FKJ;
float FK[4];
event O2P9 = event();
event D1P1 = event();
event opui = event();
event bvnb = event();
// "when started" hat block
int whenStarted1() {
Drivetrain.setDriveVelocity(100.0, percent);
Drivetrain.setTurnVelocity(100.0, percent);
while (true) {
if (Distance3_OS.objectDistance(inches) <= 30.0) {
while (Distance3_OS.isObjectDetected()) {
O2P9.broadcast();
wait(20, msec);
}
}
if (Distance4_OSL.objectDistance(inches) <= 30.0) {
while (Distance4_OSL.isObjectDetected()) {
D1P1.broadcast();
wait(20, msec);
}
}
if (Distance7_OF.objectDistance(inches) <= 30.0) {
while (Distance7_OF.isObjectDetected()) {
opui.broadcast();
wait(20, msec);
}
}
if (Distance8_OB.objectDistance(inches) <= 30.0) {
while (Distance8_OB.isObjectDetected()) {
bvnb.broadcast();
wait(20, msec);
}
}
wait(20, msec);
}
return 0;
}
// "when started" hat block
int whenStarted2() {
while (true) {
if (Distance1_DS.objectDistance(mm) <= 1.0) {
Drivetrain.stop();
Drivetrain.drive(reverse);
}
wait(20, msec);
}
return 0;
}
// "when started" hat block
int whenStarted3() {
while (true) {
if (Distance2_DSL.objectDistance(mm) <= 1.0) {
Drivetrain.stop();
Drivetrain.drive(forward);
}
wait(20, msec);
}
return 0;
}
// "when started" hat block
int whenStarted4() {
while (true) {
if (Distance9_DF.objectDistance(mm) <= 1.0) {
Drivetrain.stop();
Drivetrain.turnFor(right, 180.0, degrees, true);
Drivetrain.drive(reverse);
}
wait(20, msec);
}
return 0;
}
// "when started" hat block
int whenStarted5() {
while (true) {
if (Distance11_DB.objectDistance(mm) <= 1.0) {
Drivetrain.stop();
Drivetrain.turnFor(left, 180.0, degrees, true);
Drivetrain.drive(reverse);
}
wait(20, msec);
}
return 0;
}
// "when I receive O2P9" hat block
void onevent_O2P9_0() {
while (true) {
if (Distance3_OS.objectDistance(inches) > Distance7_OF.objectDistance(inches) > Distance4_OSL.objectDistance(inches)) {
if (Distance3_OS.objectDistance(inches) > Distance8_OB.objectDistance(inches)) {
Drivetrain.driveFor(forward, Distance2_DSL.objectDistance(inches), inches, true);
}
}
wait(20, msec);
}
}
// "when I receive D1P1" hat block
void onevent_D1P1_0() {
while (true) {
if (Distance4_OSL.objectDistance(inches) > Distance7_OF.objectDistance(inches) > Distance3_OS.objectDistance(inches)) {
if (Distance4_OSL.objectDistance(inches) > Distance8_OB.objectDistance(inches)) {
Drivetrain.driveFor(forward, Distance2_DSL.objectDistance(inches), inches, true);
}
}
wait(20, msec);
}
}
// "when I receive opui" hat block
void onevent_opui_0() {
while (true) {
if (Distance7_OF.objectDistance(inches) > Distance3_OS.objectDistance(inches) > Distance4_OSL.objectDistance(inches)) {
if (Distance7_OF.objectDistance(inches) > Distance8_OB.objectDistance(inches)) {
Drivetrain.driveFor(forward, Distance2_DSL.objectDistance(inches), inches, true);
}
}
wait(20, msec);
}
}
// "when I receive bvnb" hat block
void onevent_bvnb_0() {
while (true) {
if (Distance8_OB.objectDistance(inches) > Distance7_OF.objectDistance(inches) > Distance3_OS.objectDistance(inches)) {
if (Distance8_OB.objectDistance(inches) > Distance4_OSL.objectDistance(inches)) {
Drivetrain.driveFor(forward, Distance2_DSL.objectDistance(inches), inches, true);
}
}
wait(20, msec);
}
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// register event handlers
O2P9(onevent_O2P9_0);
D1P1(onevent_D1P1_0);
opui(onevent_opui_0);
bvnb(onevent_bvnb_0);
wait(15, msec);
vex::task ws1(whenStarted2);
vex::task ws2(whenStarted3);
vex::task ws3(whenStarted4);
vex::task ws4(whenStarted5);
whenStarted1();
}