Go to Post that is one of the funniest non-photoshoped pictures of my father i have seen... - Lil' Lavery [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
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 Yesterday, 18:40
Kyle Davis Kyle Davis is offline
Registered User
FRC #5242
 
Join Date: Jan 2017
Location: Dallas
Posts: 1
Kyle Davis is an unknown quantity at this point
SmartDashboard output help

Hi, I am having an error whenever I run certain code on the roborio.
When i commented out all of the code in method driveForward() except the variable declarations, the console doesn't output any errors, but when I uncomment and include leftEncoder.reset() and rightEncoder.reset(), I get an error that disables my robot. Any help is appreciated.

This is the code I am running:

package org.usfirst.frc.team5242.robot;

import edu.wpi.first.wpilibj.AnalogInput;
import edu.wpi.first.wpilibj.BuiltInAccelerometer;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.interfaces.Accelerometer;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboar d;

/**
* This is a sample program to demonstrate the use of a soft potentiometer and
* proportional control to reach and maintain position setpoints on an elevator
* mechanism. A joystick button is used to switch elevator setpoints.
*
* WARNING: While it may look like a good choice to use for your code if you're
* inexperienced, don't. Unless you know what you are doing, complex code will
* be much more difficult under this system. Use IterativeRobot or Command-Based
* instead if you're new.
*/
public class Robot extends SampleRobot {
//Drive Objects
BuiltInAccelerometer accel;
RobotDrive drive;
Joystick stick;
Encoder leftEncoder;
Encoder rightEncoder;
Accelerometer accelerometer;

final int kPotChannel = 1; // analog input pin
final int kMotorChannel = 7; // PWM channel
final int kJoystickChannel = 0; // usb number in DriverStation
final int kButtonNumber = 4; // joystick button

final double kSetPoints[] = { 1.0, 2.6, 4.3 }; // bottom, middle, and top
// elevator setpoints

final double kP = 1.0; // proportional speed constant
double motorSpeed;
double currentPosition; // sensor voltage reading corresponding to current
// elevator position

// make objects for the potentiometer, elevator motor controller, and
// joystick
AnalogInput potentiometer = new AnalogInput(kPotChannel);
Victor elevatorMotor = new Victor(kMotorChannel);
Joystick joystick = new Joystick(kJoystickChannel);



public Robot() {
}

public void driveForward2(float distance, float speed)
{

}

public void driveForward(float distance, float speed)
{
int pulsesPerRev = 1024;
double inchesPerRev = 6.0 * 3.141;
double currentSpeed;
double currentDistance;
double acceleration;
double deceleration;
double driveDelay;

currentSpeed = 0.0;
currentDistance = 0.0;
acceleration = 0.01;
deceleration = 0.02;
driveDelay = 0.01;



//rightEncoder.reset();
//leftEncoder.reset();

rightEncoder.setDistancePerPulse(inchesPerRev / pulsesPerRev);


/*while(currentDistance < distance)
{
SmartDashboard.putNumber("Distance", currentDistance);
if (currentSpeed < speed)
{
currentSpeed = currentSpeed + acceleration;
}
//drive.tankDrive(currentSpeed, currentSpeed);
drive.tankDrive(0, 0);
Timer.delay(driveDelay);
currentDistance = (rightEncoder.getDistance() + leftEncoder.getDistance()) / 2;
}

while (currentSpeed > 0)
{
currentSpeed = currentSpeed - deceleration;
if (currentSpeed < 0.0)
currentSpeed = 0.0;
drive.tankDrive(currentSpeed, currentSpeed);
Timer.delay(driveDelay);
}
*/
}


/**
* Runs during autonomous.
*/
@Override
public void autonomous() {
//drive.setSafetyEnabled(false);
SmartDashboard.putNumber("start go", 1);
driveForward((float) 24.0,(float) 5.0);
SmartDashboard.putNumber("stop", 5);
//drive.setSafetyEnabled(true);
}

/**
* Moves elevator to a selectable setpoint that can be changed by pressing a
* button on the joystick. Proportional control is used to reach and
* maintain the desired setpoint by obtaining values from the potentiometer
* and comparing them to the setpoint value.
*/
@Override
public void operatorControl() {
boolean buttonState;
boolean prevButtonState = false;

int index = 0; // setpoint array index
double currentSetpoint; // holds desired setpoint
currentSetpoint = kSetPoints[0]; // set to first setpoint

while (isOperatorControl() && isEnabled()) {
buttonState = joystick.getRawButton(kButtonNumber); // check if
// button is
// pressed

// if button has been pressed and released once
if (buttonState && !prevButtonState) {
index = (index + 1) % kSetPoints.length; // increment set point,
// reset if at end
// of
// array
currentSetpoint = kSetPoints[index]; // set setpoint
}
prevButtonState = buttonState; // record previous button state

currentPosition = potentiometer.getAverageVoltage(); // get position
// value
motorSpeed = (currentPosition - currentSetpoint) * kP; // convert
// position
// error
// to
// speed
elevatorMotor.set(motorSpeed); // drive elevator motor
}
}

/**
* Runs during test mode
*/
@Override
public void test() {
}
}
Reply With Quote
  #2   Spotlight this post!  
Unread Yesterday, 19:13
forbes's Avatar
forbes forbes is offline
Software developer
AKA: Evan Forbes
FRC #3507 (Ubotics), 694 (StuyPulse)
Team Role: Mentor
 
Join Date: Apr 2013
Rookie Year: 2012
Location: New York City
Posts: 162
forbes is a splendid one to beholdforbes is a splendid one to beholdforbes is a splendid one to beholdforbes is a splendid one to beholdforbes is a splendid one to beholdforbes is a splendid one to beholdforbes is a splendid one to beholdforbes is a splendid one to behold
Re: SmartDashboard output help

Do you ever initialize the encoder objects?
For example:
leftEncoder = new Encoder(0, 1, false, Encoder.EncodingType.k4X);

http://first.wpi.edu/FRC/roborio/rel...j/Encoder.html


Also for future reference, it would be helpful to post the entire error you get in addition to your code
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 03:01.

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