Hello! We are coding a robot (her name is Artemis) and she's giving us some trouble. We are 1st alternates for the WA state SkillsUSA robotics competition in March, so we are trying to be prepared just in case. We are very new to coding, so our issues could probably just be something we're not catching because we're new to this.
Artemis uses Pitsco's Tele-Op, DC Motor Expansion Controller, and PRIZM Brain. Artemis uses Mecanum wheels, which have been giving us a lot of trouble. We're using Arduino IDE with the Uno library to code her.
Our main issue is that an error keeps popping up after we compile our code. It says "unexpected initializer" whenever we compile it, and we have no idea how to fix this. If anyone can help us out, we'd really appreciate it!
Our code is as follows:
#include <SPI.h>
#include <TELEOP.h>
#include <PRIZM.h>
void runOpMode() throws InterruptedException {
// Declare our motors
// Make sure your ID's match your configuration
DcMotor frontLeftMotor = hardwareMap.dcMotor.get("frontLeftMotor");
DcMotor backLeftMotor = hardwareMap.dcMotor.get("backLeftMotor");
DcMotor frontRightMotor = hardwareMap.dcMotor.get("frontRightMotor");
DcMotor backRightMotor = hardwareMap.dcMotor.get("backRightMotor");
// Reverse the right side motors. This may be wrong for your setup.
// If your robot moves backwards when commanded to go forwards,
// reverse the left side instead.
// See the note about this earlier on this page.
frontRightMotor.setDirection(DcMotorSimple.Direction.REVERSE);
backRightMotor.setDirection(DcMotorSimple.Direction.REVERSE);
waitForStart();
if (isStopRequested()) return;
while (opModeIsActive()) {
double y = -gamepad1.left_stick_y; // Remember, Y stick value is reversed
double x = gamepad1.left_stick_x * 1.1; // Counteract imperfect strafing
double rx = gamepad1.right_stick_x;
// Denominator is the largest motor power (absolute value) or 1
// This ensures all the powers maintain the same ratio,
// but only if at least one is out of the range [-1, 1]
double denominator = Math.max(Math.abs(y) + Math.abs(x) + Math.abs(rx), 1);
double frontLeftPower = (y + x + rx) / denominator;
double backLeftPower = (y - x + rx) / denominator;
double frontRightPower = (y - x - rx) / denominator;
double backRightPower = (y + x - rx) / denominator;
frontLeftMotor.setPower(frontLeftPower);
backLeftMotor.setPower(backLeftPower);
frontRightMotor.setPower(frontRightPower);
backRightMotor.setPower(backRightPower);
}
}