|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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(); } |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|