![]() |
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(); } |
Re: Arduino and FRC
Hello,
Quote:
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. |
Re: Arduino and FRC
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 |
Re: Arduino and FRC
Quote:
|
Re: Arduino and FRC
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 ) |
| All times are GMT -5. The time now is 20:14. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi