Go to Post Yeah After we decided not to do autonomous, the robot took matters into it's own hand. i'd bet it would get it's self DQ'd... or an award. - GMKlenklen [more]
Home
Go Back   Chief Delphi > Technical > Control System
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 13-04-2014, 10:51
tanguma26 tanguma26 is offline
Registered User
FRC #3999
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Killeen
Posts: 48
tanguma26 is an unknown quantity at this point
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();
}
Reply With Quote
  #2   Spotlight this post!  
Unread 19-04-2014, 00:09
tech2077 tech2077 is offline
Registered User
AKA: Matthew Skolaut
FRC #3847 (Spectrum 3847)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Houston
Posts: 21
tech2077 is an unknown quantity at this point
Re: Arduino and FRC

Hello,

Quote:
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.
Reply With Quote
  #3   Spotlight this post!  
Unread 24-04-2014, 18:32
tanguma26 tanguma26 is offline
Registered User
FRC #3999
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Killeen
Posts: 48
tanguma26 is an unknown quantity at this point
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
Reply With Quote
  #4   Spotlight this post!  
Unread 24-04-2014, 18:56
kgzak's Avatar
kgzak kgzak is offline
Registered User
AKA: Kris
FRC #4392 (Decievers) FRC #2075 (Enigma)
Team Role: College Student
 
Join Date: Dec 2008
Rookie Year: 2008
Location: Grand Rapids, Michigan
Posts: 418
kgzak is a splendid one to beholdkgzak is a splendid one to beholdkgzak is a splendid one to beholdkgzak is a splendid one to beholdkgzak is a splendid one to beholdkgzak is a splendid one to beholdkgzak is a splendid one to behold
Re: Arduino and FRC

Quote:
Originally Posted by tanguma26 View Post
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.
Reply With Quote
  #5   Spotlight this post!  
Unread 28-04-2014, 03:21
brentyi brentyi is offline
Member
FRC #0846 (The Funky Monkeys)
Team Role: Student
 
Join Date: Dec 2012
Rookie Year: 2011
Location: San Jose, CA
Posts: 4
brentyi is an unknown quantity at this point
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 )

Last edited by brentyi : 28-04-2014 at 03:23. Reason: I'm stupid.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 05:31.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi