Go to Post I was watching the webcast when that score was posted and thought to myself, "What did they do, steal a donut from Dave?" - MissInformation [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 29-01-2015, 18:14
CavbotRyche CavbotRyche is offline
Registered User
FRC #5020
 
Join Date: Jan 2015
Location: Spartanburg
Posts: 6
CavbotRyche is an unknown quantity at this point
Need help with conveyor belt programming

Trying to get the programming in our robot finished and we are struggling. Here is the program. We are new and not very experienced any help or advice would be awesome.




import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.RobotDrive.MotorType;
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.Timer;

/**
* This is a demo program showing how to use Mecanum control with the RobotDrive class.
*/
public class Buttontest extends SampleRobot {

RobotDrive robotDrive;
Joystick stick;

// Channels for the wheels
final int frontLeftChannel = 0;
final int rearLeftChannel = 1;
final int frontRightChannel = 2;
final int rearRightChannel = 3;

// The channel on the driver station that the joystick is connected to
final int joystickChannel = 3;
private Object conveyorMotor;
private Object joystick;
private Object set;

public Buttontest() {
robotDrive = new RobotDrive(frontLeftChannel, rearLeftChannel, frontRightChannel, rearRightChannel);
robotDrive.setExpiration(0.1);

stick = new Joystick(joystickChannel);
}


/**
* Runs the motors with Mecanum drive.
*/
public void operatorControl() {
robotDrive.setSafetyEnabled(true);
while (isOperatorControl() && isEnabled()) {

// Use the joystick X axis for lateral movement, Y axis for forward movement, and Z axis for rotation.
// This sample does not use field-oriented drive, so the gyro input is set to zero.
robotDrive.arcadeDrive(-stick.getY(), -stick.getX());
Timer.delay(0.005); // wait 5ms to avoid hogging CPU cycles
}
}
//Conveyor Belt
boolean belt = false;
boolean toggle = true;

if (toggle && Button) {
toggle = false;
if (belt) {
belt= false;
conveyorMotor.set(1);
}else{
belt= true;
conveyorMotor.set(0);
}
}else if(belt == FALSE){
toggle = true;
}
Reply With Quote
  #2   Spotlight this post!  
Unread 30-01-2015, 10:20
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,729
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Need help with conveyor belt programming

Just reposting this in code tags for readability purposes. To use code tags place a [/code] at the end and a [code] at the beginning.

Am I correct in assuming you are getting syntax errors?

Code:
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.RobotDrive.MotorType;
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.Timer;

/**
* This is a demo program showing how to use Mecanum control with the RobotDrive class.
*/
public class Buttontest extends SampleRobot {

	RobotDrive robotDrive;
	Joystick stick;

	// Channels for the wheels
	final int frontLeftChannel	= 0;
	final int rearLeftChannel	= 1;
	final int frontRightChannel	= 2;
	final int rearRightChannel	= 3;

	// The channel on the driver station that the joystick is connected to
	final int joystickChannel	= 3;
	private Object conveyorMotor;
	private Object joystick;
	private Object set;

	public Buttontest() {
		robotDrive = new RobotDrive(frontLeftChannel, rearLeftChannel, frontRightChannel, rearRightChannel);
		robotDrive.setExpiration(0.1);

		stick = new Joystick(joystickChannel);
	}


	/**
	* Runs the motors with Mecanum drive.
	*/
	public void operatorControl() {
		robotDrive.setSafetyEnabled(true);
		while (isOperatorControl() && isEnabled()) {

			// Use the joystick X axis for lateral movement, Y axis for forward movement, and Z axis for rotation.
			// This sample does not use field-oriented drive, so the gyro input is set to zero.
			robotDrive.arcadeDrive(-stick.getY(), -stick.getX());
			Timer.delay(0.005);	// wait 5ms to avoid hogging CPU cycles
		}
	}
	
	//Conveyor Belt
	boolean belt = false;
	boolean toggle = true;

	if (toggle && Button) {
		toggle = false;
		if (belt) {
			belt= false;
			conveyorMotor.set(1);
		}else{
			belt= true;
			conveyorMotor.set(0);
		}
	}else if(belt == FALSE){
		toggle = true;
	}

Last edited by notmattlythgoe : 30-01-2015 at 10:24.
Reply With Quote
  #3   Spotlight this post!  
Unread 31-01-2015, 06:58
CavbotRyche CavbotRyche is offline
Registered User
FRC #5020
 
Join Date: Jan 2015
Location: Spartanburg
Posts: 6
CavbotRyche is an unknown quantity at this point
Re: Need help with conveyor belt programming

Thank you for doing that! Did not know how to. We have our robot driving with this code but the conveyor motor is not responding to joystick button commands. We are using a Victor 888 as a servo and want button 3 and 4 to be used for up and down movement on our Logitech Extreme 3D Pro.
Reply With Quote
  #4   Spotlight this post!  
Unread 31-01-2015, 09:00
TFleig78's Avatar
TFleig78 TFleig78 is offline
Registered User
AKA: Tyler
FRC #0078 (Air Strike)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Rhode Island
Posts: 58
TFleig78 will become famous soon enoughTFleig78 will become famous soon enough
Re: Need help with conveyor belt programming

Looks like you need to put the conveyor code within the operatorControl method.
Also you need to use the joystick method getRawButton() in order to get the state of a button.
The updated code below should work better.



Code:
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.RobotDrive.MotorType;
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.Timer;

/**
* This is a demo program showing how to use Mecanum control with the RobotDrive class.
*/
public class Buttontest extends SampleRobot {

	RobotDrive robotDrive;
	Joystick stick;

	// Channels for the wheels
	final int frontLeftChannel	= 0;
	final int rearLeftChannel	= 1;
	final int frontRightChannel	= 2;
	final int rearRightChannel	= 3;

	// The channel on the driver station that the joystick is connected to
	final int joystickChannel	= 3;
	private Object conveyorMotor;
	private Object joystick;
	private Object set;

	public Buttontest() {
		robotDrive = new RobotDrive(frontLeftChannel, rearLeftChannel, frontRightChannel, rearRightChannel);
		robotDrive.setExpiration(0.1);

		stick = new Joystick(joystickChannel);
	}


	/**
	* Runs the motors with Mecanum drive.
	*/
	public void operatorControl() {
		robotDrive.setSafetyEnabled(true);
		while (isOperatorControl() && isEnabled()) {

			// Use the joystick X axis for lateral movement, Y axis for forward movement, and Z axis for rotation.
			// This sample does not use field-oriented drive, so the gyro input is set to zero.
			robotDrive.arcadeDrive(-stick.getY(), -stick.getX());


                        if (stick.getRawButton(3)) {//if button 3 is pressed go full speed up
		               conveyorMotor.set(1);
                        }
		        else if (stick.getRawButton(4)) {//button 4, full speed down
			       conveyorMotor.set(-1);
                        }
                        else{
                               conveyorMotor.set(0); //no button pressed, stop
                        }


			Timer.delay(0.005);	// wait 5ms to avoid hogging CPU cycles
		}
	}
	
	
}
Reply With Quote
  #5   Spotlight this post!  
Unread 02-02-2015, 05:58
CavbotRyche CavbotRyche is offline
Registered User
FRC #5020
 
Join Date: Jan 2015
Location: Spartanburg
Posts: 6
CavbotRyche is an unknown quantity at this point
Re: Need help with conveyor belt programming

I will try your suggestions at our next meeting. I am also playing with Labview. I will keep you updated.
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 00:42.

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