Go to Post "Mentors Only Work When Being Calibrated". - Calvin Hartley [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #5   Spotlight this post!  
Unread 16-11-2013, 21:43
Jay_To_The_Be's Avatar
Jay_To_The_Be Jay_To_The_Be is offline
Programmer - MOE365
AKA: Jeremiah Batista
FRC #0365 (Team 365 - Miracle Workerz)
Team Role: Programmer
 
Join Date: Oct 2013
Rookie Year: 2013
Location: United States
Posts: 8
Jay_To_The_Be is an unknown quantity at this point
Re: Which communication protocol is best?

I'm just modifying the code I wrote for a practice bot. I want to replace the joystick x&y variables with the x&y variables being sent from processing. I understand the the workstation, I just don't know how to setup up the connection between the cRIO and PROCESSING , and how to separate a comma-delimited string and make those values.

This is my original code that i'm modifying:
Code:
#include "WPILib.h"

class Stan : public IterativeRobot {

Jaguar *leftFront;
Jaguar *leftRear;
Jaguar *rightFront;
Jaguar *rightRear;

Joystick *driveStick;

Encoder *leftEncoder;
Encoder *rightEncoder;

Solenoid *shifter;


Gyro *moeGyro;

Compressor *moeCompressor;

DriverStation *ds;

DriverStationLCD *dsLCD;

int teleopLoop;
int disabledLoop;
int autoLoop;

public:
	
	Stan(void)			{
			
			leftFront = new Jaguar(1);
			leftRear = new Jaguar(2);
			rightFront = new Jaguar(3);
			rightRear = new Jaguar(4);
			
			driveStick = new Joystick(1);
			
			leftEncoder = new Encoder(1,2,true,Encoder::k1X);
			rightEncoder = new Encoder(3,4,false,Encoder::k1X);

			moeGyro = new Gyro(1);
			
			moeCompressor = new Compressor(7,1);
			
			ds = DriverStation::GetInstance();
			
			dsLCD = DriverStationLCD::GetInstance();
			
	}
			
	void RobotInit(void)	{
				
		leftEncoder->Start();
		rightEncoder->Start();
				
		moeCompressor->Start();
					
		shifter->Set(false);
	}

	void DisabledInit(void)		{

		disabledLoop = 0;
		
	}
	
	void TeleopInit(void)	{
	
		teleopLoop = 0;
	
	}

	void AutonomousInit(void)	{
		
		autoLoop = 0;
		
		leftEncoder->Reset();
		rightEncoder->Reset();
		
		moeGyro->Reset();
	
	}
	
	void DisablePeriodic(void)	{
		
		disabledLoop = disabledLoop +1;
	
	}
	
	void TeleopPeriodic(void)	{
		
		teleopLoop++;
		
		float X = driveStick->GetX();
		float Y = driveStick->GetY();
		
		if (X<0.1 && X>0.1)	X = 0.0;
		
		if (Y<0.1 && Y>0.1)	Y=0.0;
		
		X = Y + X;
		Y = X - Y;
		
		moeDrive(X, Y);
		
		controlShifter();
		
		int leftDist = leftEncoder->GetRaw();
		
		if (teleopLoop % 10==0)	{
			dsLCD->Printf(DriverStationLCD::kUser_Line1, 1, "L = %d", leftDist);
			
			dsLCD->UpdateLCD();
		}
	
	}
		
	void AutonomousPeriodic(void)	{
		
		autoLoop++;
		
		if (ds->GetDigitalIn(1))	{
			autoLoop++;
		}
	
	}
	
	void controlShifter(void)	{
		if (driveStick->GetTrigger())	{
			shifter->Set(true);
			}
		else	{
			shifter->Set(false);
			}
	}
	void moeDrive(float leftSpeed, float rightSpeed)	{
		
		if (leftSpeed > 1.0) leftSpeed = 1.0;
		else if (leftSpeed < -1.0) leftSpeed = -1.0;

		if (rightSpeed > 1.0) rightSpeed = 1.0;
		else if (rightSpeed < -1.0) rightSpeed = -1.0;
		
		leftFront->Set(leftSpeed);
		leftRear->Set(leftSpeed);
		rightFront->Set(rightSpeed);
		rightRear->Set(rightSpeed);
	}
	
};

START_ROBOT_CLASS(Stan);
Reply With Quote
 


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 14:37.

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