Go to Post There's no feeling quite like that one you get when you're behind the diamond plate controlling a metal beast that you've put your blood (literally), sweat (more literally), and tears (probably literally) into, and it working. Undescribable. - scali [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

 
Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1   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
  #2   Spotlight this post!  
Unread 16-11-2013, 22:23
Domenic Rodriguez's Avatar
Domenic Rodriguez Domenic Rodriguez is offline
Registered User
FRC #0316 (LuNaTeCs)
Team Role: College Student
 
Join Date: Sep 2010
Rookie Year: 2011
Location: Grove City, PA
Posts: 213
Domenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura about
Re: Which communication protocol is best?

You should take a look at this thread, as it discusses TCP/IP communication with WindRiver C++: http://www.chiefdelphi.com/forums/sh...d.php?t=100810

Mentioned within is Team 3574's 2012 code, which used a TCP to send vision data from the driver station laptop. Here's a link: https://github.com/jacob9706/HighTekerz2012. You might be able to use it as a starting point.
__________________

LuNaTeCs - Learning Under Nurturing Adults Teaching Engineering Concepts and Skills - Small and Mighty!

FRC 316 LuNaTeCs - Student (2011-2014), Lead Programmer (2011-2014), Team Captain (2013-2014), Operator (2013), Drive Coach (2014), Mentor (2015-????)
'11 Philly Regional Finalists, '13 Chestnut Hill Finalists, '13 Lenape Champions, '13 Archimedes Division, '14 Chestnut Hill Champions, '14 Lenape Champions
FTC 7071 EngiNerds - Founding Advisor (2013-2014) | FRC 5420 Velocity - Founding Advisor (2015)
Grove City College Class of '18, Electrical/Computer Engineering (B.S.E.E)

Reply With Quote
  #3   Spotlight this post!  
Unread 18-11-2013, 01:24
RyanCahoon's Avatar
RyanCahoon RyanCahoon is offline
Disassembling my prior presumptions
FRC #0766 (M-A Bears)
Team Role: Engineer
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Mountain View
Posts: 689
RyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond repute
Re: Which communication protocol is best?

Quote:
Originally Posted by Jay_To_The_Be View Post
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.
Quote:
Originally Posted by DomenicR View Post
Mentioned within is Team 3574's 2012 code, which used a TCP to send vision data from the driver station laptop.
You can also check out the Network Tables code in the WPILib source code, which includes a TCP server. VxWorks looks like it basically uses the Berkeley/POSIX sockets API, so any resources on the Internet for Linux or Unix socket code should work as well. The code is a little extensive to replicate in-thread.

As for parsing delimited strings, here's some code for that separates numbers delimited by whitespace:

Spoiler for Parse whitespace-delimited numbers:

Code:
#include <string>
#include <sstream>
#include <iterator>
#include <vector>

#include <iostream>

int main(int argc, char **argv)
{
	if (argc != 2)
		return 1;
	
	std::string input(argv[1]);
	std::stringstream ss(input);
	std::vector<double> parts((std::istream_iterator<double>(ss)), (std::istream_iterator<double>()));
	if (ss.fail() && !ss.eof())
	{
		std::cout << "Data format error" << std::endl;
		return -1;
	}
	
	for(int i=0; i < parts.size(); ++i)
	{
		std::cout << parts[i] << std::endl;
	}
	
	return 0;
}


if you need comma to be delimiters as well, the code gets a bit more complicated:

Spoiler for Parse comma- and whitespace-delimited numbers:

Code:
#include <string>
#include <sstream>
#include <vector>
#include <cctype>

#include <iostream>

int main(int argc, char **argv)
{
	if (argc != 2)
		return 1;
	
	std::string input(argv[1]);
	std::stringstream ss(input);
	std::vector<double> parts;
	double val;
	
	while(ss >> val)
	{
		parts.push_back(val);
		
		while(std::isspace(ss.peek()) || ss.peek() == ',')
			ss.ignore();
	}
	if (!ss.eof())
	{
		std::cout << "Data format error" << std::endl;
		return -1;
	}
	
	for(int i=0; i < parts.size(); ++i)
	{
		std::cout << parts[i] << std::endl;
	}
	
	return 0;
}
__________________
FRC 2046, 2007-2008, Student member
FRC 1708, 2009-2012, College mentor; 2013-2014, Mentor
FRC 766, 2015-, Mentor
Reply With Quote
  #4   Spotlight this post!  
Unread 16-11-2013, 22:57
ekapalka's Avatar
ekapalka ekapalka is offline
Registered User
FRC #3216
 
Join Date: Dec 2012
Location: Bermuda
Posts: 277
ekapalka has a spectacular aura aboutekapalka has a spectacular aura about
Re: Which communication protocol is best?

Quote:
Originally Posted by Jay_To_The_Be View Post
PROCESSING
Thanks for the extra bold extra italicized clarification. Sorry, sir, but I don't believe I know the solution to your problem.
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 12:53.

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