View Single Post
  #9   Spotlight this post!  
Unread 19-09-2015, 15:14
cwengineer's Avatar
cwengineer cwengineer is offline
Engineering Mentor
AKA: Corey
FRC #3265 (RoboTribe)
Team Role: Engineer
 
Join Date: Sep 2015
Rookie Year: 2007
Location: Georgia
Posts: 6
cwengineer is an unknown quantity at this point
Re: RobotOpen Digital Sidecar Programming

All values are updating to the DS, but no PWM output from the DSC.

Code:
#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;
}