Log in

View Full Version : RobotOpen Digital Sidecar Programming


cwengineer
18-09-2015, 21:42
I am working on an off-season project using an Arduino and a the RobotOpen Control Shield connected to the DSC. I have the Arduino communicating with the RobotOpen DS.
The problem I am running into is the code to interface with the DSC.
Using RobotOpen Documentation (https://robotopen.readthedocs.org/en/latest/index.html) I tried ROPWM but the DSC PWM pins don't seem to output.

Does anyone have any experience with the RobotOpen Controller running the DSC?

My code is pulled right from their ArcadeDrive example and my left/right motors are plugged into the DSC PWM 0/1.
My ultrasonic sensor portion of the code works fine.


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

/* I/O Setup */
ROJoystick usb1(1); // Joystick #1
ROPWM leftDrive(0);
ROPWM rightDrive(1);

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

/* This is your primary robot loop - all of your code
* should live here that allows the robot to operate
*/
void enabled() {
int leftPower = constrain((usb1.rightY() + usb1.rightX()), 0, 255);
int rightPower = constrain((usb1.rightY() - usb1.rightX()), 0, 255);

leftDrive.write(leftPower);
rightDrive.write(rightPower);

}

/* This is called while the robot is disabled
* PWMs and Solenoids are automatically disabled
*/
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("Distance", SonarRead(0));
}

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

int SonarRead(byte anPin) {
return (analogRead(anPin) + 2) / 2;
}

ajlapp
19-09-2015, 08:54
Are you getting feedback lights from the shield? Green for enabled and red for disabled?

Are you using the Chrome based driver station?

Are you using the most up to date version of the RobotOpen library?

What Arduino IDE version are you using?

cwengineer
19-09-2015, 11:04
The enable/disable lights on the shield were working but after testing a couple things this morning they aren't working now.
I am using the Chrome DS.
I can't find a version for the RO library, but I believe I have the most recent.
I am using Arduino IDE 1.6.5.

Should I be using the RobotOpenShield Library or just the RobotOpen Library?
The shield did not come with any documentation.

ajlapp
19-09-2015, 11:09
You should be using the "shield" version of the library. The most up to date version is here:

https://github.com/221robotics/RobotOpen-Shield-Library/archive/master.zip

What Arduino board are you using?

cwengineer
19-09-2015, 12:05
I am using the AndyMark Ethernet Arduino.
I tried deleting the old library, downloading the new library you sent, restarting the Arduino IDE and using the example code from ArcadeDrive.

I can connect, the enable/disable LEDs work, but still no signal passed to the DSC PWM channels. I tried swapping out the DSC and the ribbon cable, but still nothing.

Any ideas?

ajlapp
19-09-2015, 14:07
Are you confident that the pwm cable is good?

Is the ribbon cable fully seated?

Is the speed controller functioning properly?

Is your joystick actually sending data? You can check this by "publishing" your power value to the dashboard.

cwengineer
19-09-2015, 14:42
I plugged in a couple of servos to test the PWM outputs and still nothing.
The cable is seated and the joystick is sending data to the Arduino and back when enabled.

I've tested the digital IO on the DSC and it works.
I've also tested the analog, but that seems to be a direct connection to the Arduino analog pins, so that's probably not helpful.

Could it be the ATMega on the shield? How can I go about testing that?

ajlapp
19-09-2015, 14:52
Can you re-post your code now that you've updated the library.

cwengineer
19-09-2015, 15:14
All values are updating to the DS, but no PWM output from the DSC.


#include <SPI.h>
#include <Ethernet.h>
#include <EEPROM.h>
#include <RobotOpenSH.h>

/* I/O Setup */
ROJoystick usb1(1); // Joystick #1
ROPWM leftDrive(0);
ROPWM rightDrive(1);

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

}

/* This is your primary robot loop - all of your code
* should live here that allows the robot to operate
*/
void enabled() {
int leftPower = constrain((usb1.leftY() + usb1.leftX()), 0, 255);
int rightPower = constrain((usb1.leftY() - usb1.leftX()), 0, 255);

leftDrive.write(leftPower);
rightDrive.write(rightPower);

}

/* This is called while the robot is disabled
* PWMs and Solenoids are automatically disabled
*/
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("Left", constrain((usb1.leftY() + usb1.leftX()), 0, 255));
RODashboard.publish("Right", constrain((usb1.leftY() - usb1.leftX()), 0, 255));
RODashboard.publish("Digital", digitalRead(SIDECAR_DIGITAL1));
RODashboard.publish("Distance", SonarRead(0));
}

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

int SonarRead(byte anPin) {
return (analogRead(anPin) + 2) / 2;
}

cwengineer
19-09-2015, 21:54
I took a break from this robot, then swapped out the PWM cables, restarted the laptop, reloaded the code, tested again and it works beautifully now.
I don't think it was the cables and am still a little bugged by what was causing the problem, but at this point I'm glad it's working.

Is there a spec sheet on this shield to tell me which Arduino pins are being used for what? I want to know which pins are open to use for custom circuits.