Hello, our team has been trying to integrate a functioning ColorSensor program (that was adapted from the BasicColorSensor) into out also functioning autonomous mode. However when inserting the ColorSensor program (after making adjustments) and building we are returning with numerous "cannot find symbol:" errors. We have attempted to define all of the unfound symbols. Unfortunately we cannot seem to correct relativeLayout, as it returns "expecting <identifier>". Any Help would be greatly appreciated!
Below is out current Autonomous program:
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMo de;
import com.qualcomm.robotcore.hardware.NormalizedColorSen sor;
import com.qualcomm.robotcore.hardware.SwitchableLight;
import com.qualcomm.robotcore.hardware.NormalizedRGBA;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous ;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.util.ElapsedTime;
import com.qualcomm.robotcore.util.Range;
import android.app.Activity;
import android.graphics.Color;
import android.view.View;
@Autonomous(name="BasicOpMode_Autonomous", group="Linear Opmode")
public class BasicOpMode_Autonomous extends LinearOpMode {
private ElapsedTime runtime = new ElapsedTime();
private DcMotor left_drive;
private DcMotor right_drive;
private NormalizedColorSensor color_sensor;
private RelativeLayout;
@Override
public void runOpMode() {
telemetry.addData("Status", "Initialized");
telemetry.update();
left_drive = hardwareMap.get(DcMotor.class, "left_drive");
right_drive = hardwareMap.get(DcMotor.class, "right_drive");
waitForStart();
left_drive.setPower(1.0);
right_drive.setPower(-1.0);
ElapsedTime eTime = new ElapsedTime();
eTime.reset();
View relativeLayout;
int relativeLayoutId = hardwareMap.appContext.getResources().getIdentifie r("RelativeLayout", "id", hardwareMap.appContext.getPackageName());
relativeLayout = ((Activity) hardwareMap.appContext).findViewById(relativeLayou tId);
try {
runSample();
} finally {
relativeLayout.post(new Runnable() {
public void run() {
relativeLayout.setBackgroundColor(Color.WHITE);
}
});
}
}
protected void runSample() throws InterruptedException {
float[] hsvValues = new float[3];
final float values[] = hsvValues;
boolean bPrevState = false;
boolean bCurrState = false;
color_sensor = hardwareMap.get(NormalizedColorSensor.class, "color_sensor");
if (color_sensor instanceof SwitchableLight) {
((SwitchableLight)color_sensor).enableLight(true);
}
waitForStart();
while (opModeIsActive()) {
bCurrState = gamepad1.x;
if (bCurrState != bPrevState) {
if (bCurrState) {
if (color_sensor instanceof SwitchableLight) {
SwitchableLight light = (SwitchableLight)color_sensor;
light.enableLight(!light.isLightOn());
}
}
}
bPrevState = bCurrState;
NormalizedRGBA colors = color_sensor.getNormalizedColors();
Color.colorToHSV(colors.toColor(), hsvValues);
telemetry.addLine()
.addData("H", "%.3f", hsvValues[0])
.addData("S", "%.3f", hsvValues[1])
.addData("V", "%.3f", hsvValues[2]);
telemetry.addLine()
.addData("r", "%.3f", colors.red)
.addData("b", "%.3f", colors.blue);
int color = colors.toColor();
telemetry.addLine("raw Android color: ")
.addData("r", "%02x", Color.red(color))
.addData("b", "%02x", Color.blue(color));
float max = Math.max(Math.max(Math.max(colors.red, colors.green), colors.blue), colors.alpha);
colors.red /= max;
colors.green /= max;
colors.blue /= max;
color = colors.toColor();
telemetry.addLine("normalized color: ")
.addData("r", "%02x", Color.red(color))
.addData("b", "%02x", Color.blue(color));
telemetry.update();
Color.RGBToHSV(Color.red(color), Color.green(color), Color.blue(color), hsvValues);
RelativeLayout.post(new Runnable() {
public void run() {
relativeLayout.setBackgroundColor(Color.HSVToColor (0xff, values));
}
});
}
if(Color.red(color) > Color.blue(color)){
while(eTime.time() < .5){}
left_drive.setPower(-1.0);
right_drive.setPower(1.0);
eTime.reset();
while(eTime.time() < 2.5){}
// Show the elapsed game time and wheel power.
telemetry.addData("Status", "Run Time: " + runtime.toString());
telemetry.update();
}
}
}
Below I've attached the error that returns when building. Thank you!
Below is out current Autonomous program:
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMo de;
import com.qualcomm.robotcore.hardware.NormalizedColorSen sor;
import com.qualcomm.robotcore.hardware.SwitchableLight;
import com.qualcomm.robotcore.hardware.NormalizedRGBA;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous ;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.util.ElapsedTime;
import com.qualcomm.robotcore.util.Range;
import android.app.Activity;
import android.graphics.Color;
import android.view.View;
@Autonomous(name="BasicOpMode_Autonomous", group="Linear Opmode")
public class BasicOpMode_Autonomous extends LinearOpMode {
private ElapsedTime runtime = new ElapsedTime();
private DcMotor left_drive;
private DcMotor right_drive;
private NormalizedColorSensor color_sensor;
private RelativeLayout;
@Override
public void runOpMode() {
telemetry.addData("Status", "Initialized");
telemetry.update();
left_drive = hardwareMap.get(DcMotor.class, "left_drive");
right_drive = hardwareMap.get(DcMotor.class, "right_drive");
waitForStart();
left_drive.setPower(1.0);
right_drive.setPower(-1.0);
ElapsedTime eTime = new ElapsedTime();
eTime.reset();
View relativeLayout;
int relativeLayoutId = hardwareMap.appContext.getResources().getIdentifie r("RelativeLayout", "id", hardwareMap.appContext.getPackageName());
relativeLayout = ((Activity) hardwareMap.appContext).findViewById(relativeLayou tId);
try {
runSample();
} finally {
relativeLayout.post(new Runnable() {
public void run() {
relativeLayout.setBackgroundColor(Color.WHITE);
}
});
}
}
protected void runSample() throws InterruptedException {
float[] hsvValues = new float[3];
final float values[] = hsvValues;
boolean bPrevState = false;
boolean bCurrState = false;
color_sensor = hardwareMap.get(NormalizedColorSensor.class, "color_sensor");
if (color_sensor instanceof SwitchableLight) {
((SwitchableLight)color_sensor).enableLight(true);
}
waitForStart();
while (opModeIsActive()) {
bCurrState = gamepad1.x;
if (bCurrState != bPrevState) {
if (bCurrState) {
if (color_sensor instanceof SwitchableLight) {
SwitchableLight light = (SwitchableLight)color_sensor;
light.enableLight(!light.isLightOn());
}
}
}
bPrevState = bCurrState;
NormalizedRGBA colors = color_sensor.getNormalizedColors();
Color.colorToHSV(colors.toColor(), hsvValues);
telemetry.addLine()
.addData("H", "%.3f", hsvValues[0])
.addData("S", "%.3f", hsvValues[1])
.addData("V", "%.3f", hsvValues[2]);
telemetry.addLine()
.addData("r", "%.3f", colors.red)
.addData("b", "%.3f", colors.blue);
int color = colors.toColor();
telemetry.addLine("raw Android color: ")
.addData("r", "%02x", Color.red(color))
.addData("b", "%02x", Color.blue(color));
float max = Math.max(Math.max(Math.max(colors.red, colors.green), colors.blue), colors.alpha);
colors.red /= max;
colors.green /= max;
colors.blue /= max;
color = colors.toColor();
telemetry.addLine("normalized color: ")
.addData("r", "%02x", Color.red(color))
.addData("b", "%02x", Color.blue(color));
telemetry.update();
Color.RGBToHSV(Color.red(color), Color.green(color), Color.blue(color), hsvValues);
RelativeLayout.post(new Runnable() {
public void run() {
relativeLayout.setBackgroundColor(Color.HSVToColor (0xff, values));
}
});
}
if(Color.red(color) > Color.blue(color)){
while(eTime.time() < .5){}
left_drive.setPower(-1.0);
right_drive.setPower(1.0);
eTime.reset();
while(eTime.time() < 2.5){}
// Show the elapsed game time and wheel power.
telemetry.addData("Status", "Run Time: " + runtime.toString());
telemetry.update();
}
}
}
Below I've attached the error that returns when building. Thank you!
Comment