We are trying to use the vision sensor to count the cubes that we have collected and also to sort them by colours. We have tried configuring the sensor multiple times and it seems to be able to identify the different colours. However, when we try and count the ones that it has seen and print them on the brain screen, only the purple seems to count. It is programmed to take a snap shot every second. Why aren’t the other colours being counted? Our code is attached.
Thanks,
56J
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// CubeCounter vision 10
// ---- END VEXCODE CONFIGURED DEVICES ----
#include “vex.h”
using namespace vex;
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
//task TowerCount;
float purpleCubeCount = 0;
float greenCubeCount = 0;
float orangeCubeCount = 0;
while(true){
CubeCounter.takeSnapshot(1);
if (CubeCounter.largestObject.exists == true && CubeCounter.largestObject.width>=5 && CubeCounter.takeSnapshot(CubeCounter__PURPLE_CUBE) == true){
purpleCubeCount= purpleCubeCount + 1;
} else if (CubeCounter.largestObject.exists == true && CubeCounter.largestObject.width>=5 && CubeCounter.takeSnapshot(CubeCounter__GREEN_CUBE) == true){
greenCubeCount= greenCubeCount + 1;
} else if (CubeCounter.largestObject.exists == true && CubeCounter.largestObject.width>=5 && CubeCounter.takeSnapshot(CubeCounter__ORANGE_CUBE) == true){
orangeCubeCount= orangeCubeCount + 1;
}else{
}
Brain.Screen.printAt(1, 40,“%f”, purpleCubeCount);
Brain.Screen.printAt(1, 120,“%f”, orangeCubeCount);
Brain.Screen.printAt(1, 80,“%f”, greenCubeCount);
task::sleep(1000);
}
}
// /----------------------------------------------------------------------------/
// /* /
// / Module: main.cpp /
// / Author: C:\Users\Robotics /
// / Created: Thu Sep 26 2019 /
// / Description: V5 project /
// / /
// /----------------------------------------------------------------------------*/
// #include “vex.h”
//
// // ---- START VEXCODE CONFIGURED DEVICES ----
// // Robot Configuration:
// // [Name] [Type] [Port(s)]
//