Arduino and FRC

Hello a friend of mine and myself have been working with the arduino and the system 221 designed to use the arduino for replacement of the C-rio. Anyone has experience programming for this system or program examples for a simple tank drive?
We are trying to introduces robotics were my friend lives which is a small town in Florida and we would like to have it ready for a science fair in the fall.

I made a program and if anyone could help me to check it would be helpful Thank you.

#include <SPI.h>
#include <SD.h>
#include <Ethernet.h>
#include <Servo.h>
#include <EEPROM.h>
#include <RobotOpen.h>

/* I/O Setup */
ROJoystick usb1(1); // Joystick #1

ROPWM leftDrive(0);
ROPWM rightDrive(1);
ROPWM motor1 (2);
ROPWM motor2 (3);
ROPWM motor3 (4);
ROPWM motor4 (5);

void setup()
{
/* Initiate comms */
RobotOpen.begin(&enabled, &disabled, &timedtasks);

//Configure Ditigal I/O
pinMode(SIDECAR_DIGITAL1, OUTPUT);
pinMode(SIDECAR_DIGITAL2, OUTPUT);
pinMode(SIDECAR_DIGITAL3, OUTPUT);
pinMode(SIDECAR_DIGITAL4, OUTPUT);
}

/* This is your primary robot loop - all of your code

  • should live here that allows the robot to operate
    */
    void enabled() {
    // Constantly update PWM values with joystick values
    // Analog sticks feed back values from 0-255
    // 255 - usb1.leftY() to invert a drive
    // This contains all the motors operated by the Aurduino
    leftDrive.write(usb1.leftY());
    rightDrive.write(usb1.rightY());
    motor1.write(usb1.btnX());
    motor2.write(usb1.btnB());
    motor3.write(usb1.dPadUp());
    motor4.write(usb1.btnLShoulder());

// This contains all the DIO, most are spikes or relays.
if (usb1.btnA())
digitalWrite(SIDECAR_DIGITAL1, HIGH);
else
digitalWrite(SIDECAR_DIGITAL1, LOW);

if (usb1.btnStart())
  digitalWrite(SIDECAR_DIGITAL2, HIGH);

else
digitalWrite(SIDECAR_DIGITAL2, LOW);

 if (usb1.dPadLeft())
 digitalWrite(SIDECAR_DIGITAL3, HIGH);

else
digitalWrite(SIDECAR_DIGITAL3, LOW);

    if (usb1.dPadRight())
  digitalWrite(SIDECAR_DIGITAL4, HIGH);

else
digitalWrite(SIDECAR_DIGITAL4, LOW);

}

/* This is called while the robot is disabled

  • All outputs are automatically disabled (PWM, Solenoid, Digital Outs)
    */
    void disabled() {
    // safety code
    }

/* This loop ALWAYS runs - only place code here that can run during a disabled state

  • This is also a good spot to put driver station publish code
    */
    void timedtasks() {
    RODashboard.publish(“Uptime Seconds”, ROStatus.uptimeSeconds());
    // RODashboard.publish(“Analog0”, analogZero.read()); // Display on dashboard
    //RODashboard.debug(“voltage1”); //Arduino Reading
    //RODashboard.debug(“voltage1”);//Power board reading
    //int sensorValue = analogZero.read();
    //float voltage1 = sensorValue * (5.0 / 1023); // Volatge convertion from Arduino
    //float voltage2 = voltage1 * (12.0 / 5.0);// Coming from power board

}

// !!! DO NOT MODIFY !!!
void loop() {
RobotOpen.syncDS();
}

Hello,

motor1.write(usb1.btnX());
motor2.write(usb1.btnB());

This will not work as expected as the button functions return boolean instead of int or byte, you need to pass 0-255 to the write functions for the motors in order to have them move.

Also, in order to use the spikes, you need to use two outputs per spike relay, as it has an A and B input, in addition to ground.

Thank you for your replay and I understand what you mean with the 0-255 but could you explain a little more about the spike and the two outputs can you give me an example?

Thank you

If you want forward and off it is possible to use just one IO. Spikes have the ability to be forward and reverse which requires 2 IO channels. The 3 wires on the PWM cable are all used. On signifies if output 1 is high or low and the other specifies if out put to is high low(the outputs being the two prongs on the relay opposite of the supply side. This way you can make it drive a motor forward or backwards.

Sticking an Arduino on an old robot chassis has always sounded fun!
But, two things I noticed… (if you’re still working on this)

  1. digitalWrite() is painfully expensive; I’d recommend checking if your button state changes before updating the signal on each port.

  2. Unsure if it’s considered good practice, but digitalWrite will take a boolean, so the DIO conditions end up being redundant.
    ( both true and HIGH are just defined as 0x1, false and LOW as 0x0 )