Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   CRIO ARDUINO INTERFACE (http://www.chiefdelphi.com/forums/showthread.php?t=85826)

Robototes2412 05-17-2010 11:00 AM

CRIO ARDUINO INTERFACE
 
Hey, i got bored and wrote this:

Code:

package com.shadowh511.mayor.utils;

import edu.wpi.first.wpilibj.SerialPort;

/**
 *
 * @author Team 2412
 */
public class Arduino {
    /*
    * Hopefully, i will be able to have an arduino be hooked up to the robot
    * and communicate with the serial port.  I can use this to do many things,
    * such as maintain a LCD screen and display data on it to help the electrical
    * and mechanical teams figure out what went wrong.
    *
    * In all realism, it will most likely just be a fun cool thing for me to
    * play with :D
    */
    private SerialPort serial;

    public Arduino() {
        try {
            serial = new SerialPort(115200);
            this.serial.disableTermination();
            this.serial.print("h");
            System.out.println("Arduino Starting, waiting 0.5 seconds to get data");
            String e = this.getData();
            edu.wpi.first.wpilibj.Timer.delay(0.125);

            if(e.equals("h")) {
                System.out.println("Arduino communications locked in");
            }
        }
        catch (Exception e) {
            System.out.println("something went wrong, " + e.getMessage());
        }
    }

    public String getData() {
        try {
            return this.serial.readString();
        } catch (Exception e) {
            System.out.println("something went wrong, " + e.getMessage());
            return null;
        }
    }

    public boolean sendData(byte[] buffer) throws Exception {
        try {
            int count = buffer.length;
            this.serial.write(buffer, count);
            return true;
        } catch (Exception e) {
            System.out.println("something went wrong, " + e.getMessage());
            return false;
        }
    }
   
    public boolean printf(String data) {
        try {
            this.serial.print(data);
            return true;
        } catch (Exception e) {
            System.out.println("something went wrong, " + e.getMessage());
            return false;
        }
    }

    public String requestData() {
        try {
            this.serial.print("r");
            return this.serial.readString();
        } catch (Exception e) {
            System.out.println("something went wrong, " + e.getMessage());
            return null;
        }
    }

    public int requestData(String request) {
        try {
            this.serial.print(request);
            return NumberUtils.stringToInt(this.getData());
        } catch (Exception e) {
            System.out.println("something went wrong, " + e.getMessage());
            return 0;
        }
    }
}


Hook up an arduino to the serial port and have it run a program that toggles pin number 13. Bind a button to sending h and a button to sending l. have fun pushing the buttons, you just made a polyglot robot! :D

Jeremy Germita 05-26-2010 03:35 AM

Re: CRIO ARDUINO INTERFACE
 
I like the whole idea of this!

I had an idea like this in march, but it was far more complex.

Can I play around with it? I'd like to possibly help improve on this.

Robototes2412 05-26-2010 07:07 PM

Re: CRIO ARDUINO INTERFACE
 
all my code is gpl'd so go at it. It doesn't reliably work ATM, so can you help me fix it please?

Jeremy Germita 05-27-2010 04:54 PM

Re: CRIO ARDUINO INTERFACE
 
I'll be glad to help. I can do some testing in starting in July.
Maybe we can have a working version by the 2011 Build Season!

What seems to be the problem?

Just a thought... Does your team use CAN? If yes, I think that this could interfere with that. Maybe have an alternate mode using the ADC and the DIO. Using 2 12 bit channels of the ADC, we can have a simple protocol to convert the returned int(or is it double?) into a char.

Robototes2412 05-28-2010 10:41 AM

Re: CRIO ARDUINO INTERFACE
 
This goes directly through the serial port on the Robot.

I am working on a bit of Arduino code that will let me see if the serial port is being used for anything.

I think the following will work:
Code:

void setup() {
  Serial.begin(/*Maximum Serial Rate*/);
}

void loop() {
  Serial.println(Serial.read());
}

Assuming you have your arduino hooked up to your laptop and the robot's serial port hooked up to the arduino with the TX to RX and the ground, or Pins 2 and 5.

Jeremy Germita 05-28-2010 06:27 PM

Re: CRIO ARDUINO INTERFACE
 
That sounds like a good idea. Ill post some code of the alternate comms when I get the chance.

Jeremy Germita 05-28-2010 10:20 PM

Re: CRIO ARDUINO INTERFACE
 
here is a rough idea of the constructor


Code:

public void robotInit() {
  Arduino arduinoEx = new Arduino(CommsMode commsMode,int inChannel, int outChannel);
  Arduino arduinoAn = new Arduino(CommsMode.kAnalog, 1);    //Analog, channel 1
  Arduino arduinoDig = new Arduino(CommsMode.kDigital, 7, 8);  //Digital, Channels 7 and 8
  Arduino arduinoSer = new Arduino(CommsMode.kSerial, baudRate);  //Serial, baudRate
  Arduino arduinoI2C = new Arduino(CommsMode.kI2C, 1);
}

ControlMode - Analog(with a digital Pot), Digital(with the DIO pins of the crio and arduino), Serial, I2C, etc

int inChannel - Digital-the recieving pin
Analog-The input pin
Serial-Not Needed
I2C-The address on the bus

int OutChannel-Digital only- the sending pin

long BaudRate - Serial Only, self explanatory

I'll write something up in the library to show you how the constructors would work

Jeremy Germita 05-30-2010 04:18 AM

Re: CRIO ARDUINO INTERFACE
 
About the unreliability, could you please explain this?
Is it timing? Maybe we can do something like a signal set HIGH to indicate
an incomming serial transmission and vice versa for the cRio.

I'm not sure about the levels of the Serial port on the cRio, but maybe the
levels are different. A solution to this could be using the MAX233 level
converter IC.

How is the 'duino powered? Maybe your USB port has some problem. How
about make a power adaptor(PD-Board to 3.5mm Barrel Jack). And maybe a
filter cap to smooth out any signal problems caused by rapidly dropping
voltage due to a motor starting up or similar. The regulator on the arduino
can handle the 12 volts as long you aren't powering a current-hog(servos,
lot's of led's, etc). If you are using the LCD as you said, maybe that is
drawing abnormally large amounts of current(just a thought)

Also, can we move this to PM's or email? Perferably email. PM me if yes:D

michael714 06-07-2010 12:22 AM

Re: CRIO ARDUINO INTERFACE
 
Don't move to PM's. Other people want to add an Arduino interface to the cRio. Like me. Thanks!

Tanner 06-07-2010 07:49 AM

Re: CRIO ARDUINO INTERFACE
 
Quote:

Originally Posted by michael714 (Post 965680)
Don't move to PM's. Other people want to add an Arduino interface to the cRio. Like me. Thanks!

Ditto.

-Tanner

Robototes2412 06-07-2010 11:01 AM

Re: CRIO ARDUINO INTERFACE
 
Well, our pm convo isn't alive anymore.

As far as the interface goes, I need people to help me test it (no changes since release 0)

can someone also post a copy of the serial output of the cRIO booting? (I have no serial port :( )

Jeremy Germita 06-07-2010 12:43 PM

Re: CRIO ARDUINO INTERFACE
 
I'd like to get some javadoc stuff done before i get my new Arduino, so...

-----
Can someone bring up the rule(s) about custom circuitry?
I recall a section on this. I know that as long as it is commercially available, code and circuitry are legal, but what about the arduino perhipherals(protoshields)?
What if I want to make a custom shield that logs data on a microSD card and indicate various things with bright LED's(hypothetical)

PS The shield mentioned above exists here

PPS This shield has a prototyping area, ruling on that please!

PPPS There are other (simpler) alternatives to the hypothetical question(cRio Flash, DIO, etc), I realize this
-----

What about the arduino code? what if you wrote a Serial/I2C read-/write-er and LCD interface? Does this apply in the "Available to All Teams" rule?(Forgive me, I don't remember rule numbers, just the rules.)

-----

What if I use a custom variant of the arduino board? Like a perfboard barebones? I'm pretty sure the basic schematic of the barebones is available on the site...

-----

Not doubting this project, I just want to document this with any rules users may run into.

Tanner 06-08-2010 08:26 AM

Re: CRIO ARDUINO INTERFACE
 
Quote:

Originally Posted by jeremypg399 (Post 965723)
Can someone bring up the rule(s) about custom circuitry?
I recall a section on this. I know that as long as it is commercially available, code and circuitry are legal, but what about the arduino perhipherals(protoshields)?
What if I want to make a custom shield that logs data on a microSD card and indicate various things with bright LED's(hypothetical)

PS The shield mentioned above exists here

PPS This shield has a prototyping area, ruling on that please!

I'm no expert on rules, but looking through them you've got <R03>, <R45>F/G, <R50>, and <R68>. That's all I got for doing a quick search for "custom". I can't read them right now in depth to give a good answer, but I'll leave that to someone else.

Phototyping is always good for LEDs and whatever else you could want.

Quote:

Originally Posted by jeremypg399 (Post 965723)
What about the arduino code? what if you wrote a Serial/I2C read-/write-er and LCD interface? Does this apply in the "Available to All Teams" rule?(Forgive me, I don't remember rule numbers, just the rules.)

The building things in non-season rules? If I remember correctly, it's fine as long as its shared with other teams. 'Course again I'm no expert on the rules.

Note to self: I should work on this, I've got a arduino that needs a project.

We should set up a github to share code and manage it as it is being worked on.

-Tanner

Jeremy Germita 06-09-2010 03:45 AM

Re: CRIO ARDUINO INTERFACE
 
Tanner, Thanks for the quick rulings.
Also, I think that it is a great idea to set up a github!

Jeremy Germita 06-09-2010 10:10 AM

Re: CRIO ARDUINO INTERFACE
 
Robototes2412,
You have a google account right? You can set up a Google Code account to host this project.


All times are GMT -5. The time now is 08:11 AM.

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