Go to Post a robot can always be your girl. xcept for the fact you need to share - greencactus3 [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 26-12-2008, 02:38
kyungjin kyungjin is offline
Software Specialist
AKA: Daniel
VRC #0646
Team Role: Programmer
 
Join Date: Aug 2008
Rookie Year: 2009
Location: Honolulu, Hawaii
Posts: 65
kyungjin is an unknown quantity at this point
Send a message via AIM to kyungjin Send a message via MSN to kyungjin
Getting Familiar with Programming in WindRiver

This is my second topic on the WindRiver IDE platform. Hopefully though, this topic will be able to be more broad on understanding the specifics of code.

Anyway... I've been trying to understand the sample code and trying to make sense of the Sample Code for a few days now (I've finally installed WindRiver) and I still can't get the gist of it. There's a number of issues surrounding this problem, most of it having to do with getting used to OOP but more importantly, learning what all the new function names, keywords and operators do (for example: what the heck is '->'?).

If someone can upload the sample code (if not I'll do it a bit later...) and kinda explain some of the things in the code (like what certain functions do and what certain keywords mean), I think it'll immensely help not only me, but other people trying to understand what's in the sample code.

Thanks,
- Daniel
Reply With Quote
  #2   Spotlight this post!  
Unread 26-12-2008, 14:39
kyungjin kyungjin is offline
Software Specialist
AKA: Daniel
VRC #0646
Team Role: Programmer
 
Join Date: Aug 2008
Rookie Year: 2009
Location: Honolulu, Hawaii
Posts: 65
kyungjin is an unknown quantity at this point
Send a message via AIM to kyungjin Send a message via MSN to kyungjin
Re: Getting Familiar with Programming in WindRiver

Here's the sample source code...

Code:
#include "WPILib.h"

/**
 * This is a demo program showing the use of the RobotBase class.
 * The SimpleRobot class is the base of a robot application that will automatically call your
 * Autonomous and OperatorControl methods at the right time as controlled by the switches on
 * the driver station or the field controls.
 */
class RobotDemo : public SimpleRobot
{
	RobotDrive *myRobot; // robot drive system
	Joystick *stick; // only joystick
	DriverStation *ds; // driver station

public:
	RobotDemo(void)
	{
		ds = DriverStation::GetInstance();
		myRobot = new RobotDrive(1, 2); // create robot drive base
		stick = new Joystick(1); // create the joysticks
		GetWatchdog().SetExpiration(100);
	}

	/**
	 * Drive left & right motors for 2 seconds then stop
	 */
	void Autonomous(void)
	{
		GetWatchdog().SetEnabled(false);
		myRobot->Drive(0.5, 0.0); 	// drive forwards half speed
		Wait(2000); 				//    for 2 seconds
		myRobot->Drive(0.0, 0.0); 	// stop robot
	}

	/**
	 * Runs the motors with arcade steering. 
	 */
	void OperatorControl(void)
	{
		GetWatchdog().SetEnabled(true);
		while (IsOperatorControl())
		{
			GetWatchdog().Feed();
			myRobot->ArcadeDrive(stick); // drive with arcade style (use right stick)
		}
	}
};

START_ROBOT_CLASS(RobotDemo);
Reply With Quote
  #3   Spotlight this post!  
Unread 26-12-2008, 19:55
koreabell koreabell is offline
Team 956 Safety Captain
FRC #0956 (Eagles)
Team Role: Programmer
 
Join Date: Sep 2008
Rookie Year: 2007
Location: Oregon
Posts: 24
koreabell is an unknown quantity at this point
Re: Getting Familiar with Programming in WindRiver

I'm pretty sure you'll know most of it already, but just in case for someone else who is trying to get used to c/c++ itself, i'll explain from the very beginning

Code:
#include "WPILib.h"

/**
 * This is a demo program showing the use of the RobotBase class.
 * The SimpleRobot class is the base of a robot application that will automatically call your
 * Autonomous and OperatorControl methods at the right time as controlled by the switches on
 * the driver station or the field controls.
 */
class RobotDemo : public SimpleRobot
{
	RobotDrive *myRobot; // robot drive system
	Joystick *stick; // only joystick
	DriverStation *ds; // driver station

public:
	RobotDemo(void)
	{
		ds = DriverStation::GetInstance();
		myRobot = new RobotDrive(1, 2); // create robot drive base
		stick = new Joystick(1); // create the joysticks
		GetWatchdog().SetExpiration(100);
	}

	/**
	 * Drive left & right motors for 2 seconds then stop
	 */
	void Autonomous(void)
	{
		GetWatchdog().SetEnabled(false);
		myRobot->Drive(0.5, 0.0); 	// drive forwards half speed
		Wait(2000); 				//    for 2 seconds
		myRobot->Drive(0.0, 0.0); 	// stop robot
	}

	/**
	 * Runs the motors with arcade steering. 
	 */
	void OperatorControl(void)
	{
		GetWatchdog().SetEnabled(true);
		while (IsOperatorControl())
		{
			GetWatchdog().Feed();
			myRobot->ArcadeDrive(stick); // drive with arcade style (use right stick)
		}
	}
};

START_ROBOT_CLASS(RobotDemo);
#include "WPILib.h" <--- You're including header file called "WPILib.h" to your source to use various variables, functions, etc

class RobotDemo : public SimpleRobot <---You're declaring(and defining below) the class called "RobotDemo" which is derived from class called "SimpleRobot", and you'll access to public members of "SimpleRobot" class.
{ <--- you're now defining the class
RobotDrive *myRobot; <---you're declaring RobotDrive type pointer variable called "myRobot"
Joystick *stick; <--- you're declaring Joystick type pointer variable called "stick"
DriverStation *ds; <--- you're declaring DriverStation type pointer variable called "ds"

public: <---you're adding public members
RobotDemo(void) <---you're declaring and defining constructor
{ <--- you're now defining the constructor
ds = DriverStation::GetInstance(); <--- variable "ds" equals whatever value "GetInstance()" function under class called "DriverStation" returns
myRobot = new RobotDrive(1, 2); <--- you'll assign memory for pointer variable called "myRobot", and the size of that memory will be "RobotDrive(1,2)"
stick = new Joystick(1); <--- you'll assign memory for pointer variable called "stick", and the size of that memory will be "Joystick(1)"
GetWatchdog().SetExpiration(100); <--- you'll set the watchdog timer expiration to 100ms
} <--- you're done defining the constructor

void Autonomous(void) <--- you're declaring void type function called "Autonomous" taking no parameters
{ <--- you'll now define the function
GetWatchdog().SetEnabled(false); <--- you'll disable the watchdog timer
myRobot->Drive(0.5, 0.0); <--- execute "Drive(0.5,0.0)" using arrow operator(->) to access its(myRobot pointer's) member function
Wait(2000); <--- execute function called "Wait", taking one parameter, which value you put is 2000
myRobot->Drive(0.0, 0.0); <---- execute "Drive(0.0,0.0)" using arrow operator(->) to access its(myRobot pointer's) member function
} <--- you're done defining function


void OperatorControl(void) <--- you're declaring void type function called "OperatorControl" taking no parameters
{ <--- you're defining the function
GetWatchdog().SetEnabled(true); <--- you're setting watchdog timer
while (IsOperatorControl()) <---repeat while loop until "IsOperatorControl()" equals 0
{ <--- define while loop
GetWatchdog().Feed(); <--- feed the watchdog timer
myRobot->ArcadeDrive(stick); <---execute "ArcadeDrive" function(and parameter it takes is stick variable) using arrow operator(->) to access its(myRobot pointer's) member function
} <--- you're done defining while loop
} <--- you're done defining function

}; <--- you're done defining class

START_ROBOT_CLASS(RobotDemo); <--- you're calling function called "START_ROBOT_CLASS" with parameter "RobotDemo"
Reply With Quote
  #4   Spotlight this post!  
Unread 26-12-2008, 23:37
GGCO's Avatar
GGCO GGCO is offline
Registered User
AKA: Grant
FRC #3357
Team Role: Alumni
 
Join Date: Jan 2008
Rookie Year: 2004
Location: Michigan
Posts: 406
GGCO is a splendid one to beholdGGCO is a splendid one to beholdGGCO is a splendid one to beholdGGCO is a splendid one to beholdGGCO is a splendid one to beholdGGCO is a splendid one to beholdGGCO is a splendid one to beholdGGCO is a splendid one to behold
Send a message via AIM to GGCO
Re: Getting Familiar with Programming in WindRiver

I was wondering if windriver has something similar to MS's intellisense. I love using it in VS and was hoping to use it with WR
__________________
"Great spirits have always encountered violent opposition from mediocre minds" - Albert Einstein
The FIRST Alliance
COMETS Robotics
Website

Reply With Quote
  #5   Spotlight this post!  
Unread 27-12-2008, 07:21
jtdowney jtdowney is offline
Boiler Up
AKA: John Downey
FRC #4302 (Robophins)
Team Role: Mentor
 
Join Date: Sep 2006
Rookie Year: 2006
Location: Chicago
Posts: 300
jtdowney has a brilliant futurejtdowney has a brilliant futurejtdowney has a brilliant futurejtdowney has a brilliant futurejtdowney has a brilliant futurejtdowney has a brilliant futurejtdowney has a brilliant futurejtdowney has a brilliant futurejtdowney has a brilliant futurejtdowney has a brilliant futurejtdowney has a brilliant future
Re: Getting Familiar with Programming in WindRiver

Quote:
Originally Posted by GGCO View Post
I was wondering if windriver has something similar to MS's intellisense. I love using it in VS and was hoping to use it with WR
Eclipse, the platform Workbench is built on, has intellisense for C/C++ development. It isn't nearly as good as Visual Studio in my opinion but still there.
__________________
John Downey
Lead Robot Inspector - Purdue IndianaFIRST District
Whitney Young Magnet High School/Robophins (FRC 4302) - Mentor (2013-current)
Midwest Regional Planning Committee - Member (2012-current)
Boilermaker Regional Planning Committee - Member (2011-2014)
Robot Inspector (2008-current)
Purdue FIRST Programs - Staff Advisor (2008-2011)
Lafayette-Jefferson High School/Precision Guessworks (FRC 1646) - Mentor (2006-2011)
Reply With Quote
  #6   Spotlight this post!  
Unread 27-12-2008, 09:55
McGurky's Avatar
McGurky McGurky is offline
Geek
AKA: Kyle McGurk
FRC #1716 (Redbird Robotics)
Team Role: College Student
 
Join Date: Dec 2008
Rookie Year: 2008
Location: Houghton, MI
Posts: 291
McGurky is just really niceMcGurky is just really niceMcGurky is just really niceMcGurky is just really nice
Re: Getting Familiar with Programming in WindRiver

this is a little off topic, but where/ what version of wind river should i download?
Reply With Quote
  #7   Spotlight this post!  
Unread 27-12-2008, 12:47
jtdowney jtdowney is offline
Boiler Up
AKA: John Downey
FRC #4302 (Robophins)
Team Role: Mentor
 
Join Date: Sep 2006
Rookie Year: 2006
Location: Chicago
Posts: 300
jtdowney has a brilliant futurejtdowney has a brilliant futurejtdowney has a brilliant futurejtdowney has a brilliant futurejtdowney has a brilliant futurejtdowney has a brilliant futurejtdowney has a brilliant futurejtdowney has a brilliant futurejtdowney has a brilliant futurejtdowney has a brilliant futurejtdowney has a brilliant future
Re: Getting Familiar with Programming in WindRiver

Quote:
Originally Posted by McGurky View Post
this is a little off topic, but where/ what version of wind river should i download?
A version of WindRiver is included with the control system and it is tailored to FIRST and WPILib.
__________________
John Downey
Lead Robot Inspector - Purdue IndianaFIRST District
Whitney Young Magnet High School/Robophins (FRC 4302) - Mentor (2013-current)
Midwest Regional Planning Committee - Member (2012-current)
Boilermaker Regional Planning Committee - Member (2011-2014)
Robot Inspector (2008-current)
Purdue FIRST Programs - Staff Advisor (2008-2011)
Lafayette-Jefferson High School/Precision Guessworks (FRC 1646) - Mentor (2006-2011)
Reply With Quote
  #8   Spotlight this post!  
Unread 28-12-2008, 13:37
kyungjin kyungjin is offline
Software Specialist
AKA: Daniel
VRC #0646
Team Role: Programmer
 
Join Date: Aug 2008
Rookie Year: 2009
Location: Honolulu, Hawaii
Posts: 65
kyungjin is an unknown quantity at this point
Send a message via AIM to kyungjin Send a message via MSN to kyungjin
Re: Getting Familiar with Programming in WindRiver

To koreabell:
Thanks for taking the time to actually go down the code step by step. I've been a bit busy over the holidays and I've only gotten to read what you wrote now.

To everyone:
One thing I noticed so far in the code, is the use of an "Arcade Joystick". Is that referring to "tank-drive" type steering or to single joystick control of the robot? Also, is it possible to use a different type of steering mechanism, for example a steering wheel, to control the robot? If so, what other resources would I need and how will I be able to implement it in the source code?

Thanks for your time. I look forward to reading your replies.

- Dan
Reply With Quote
  #9   Spotlight this post!  
Unread 28-12-2008, 20:50
koreabell koreabell is offline
Team 956 Safety Captain
FRC #0956 (Eagles)
Team Role: Programmer
 
Join Date: Sep 2008
Rookie Year: 2007
Location: Oregon
Posts: 24
koreabell is an unknown quantity at this point
Re: Getting Familiar with Programming in WindRiver

Quote:
Originally Posted by kyungjin View Post
One thing I noticed so far in the code, is the use of an "Arcade Joystick". Is that referring to "tank-drive" type steering or to single joystick control of the robot? Also, is it possible to use a different type of steering mechanism, for example a steering wheel, to control the robot? If so, what other resources would I need and how will I be able to implement it in the source code?
If you read the WPI Robotics Library doxygen document (C Programming Reference),

under class "RobotDrive", there's definition for every function related to driving mechanism

Here's description for "ArcadeDrive" function
Quote:
Originally Posted by WPI Robotics Library Documentation
Arcade drive implements single stick driving. Given a single Joystick, the class assumes the Y axis for the move value and the X axis for the rotate value. (Should add more information here regarding the way that arcade drive works.)
if you want to make your robot to be controlled with tank drive system, there's a function called "TankDrive"

Description for "TankDrive" function
Quote:
Originally Posted by WPI Robotics Library Documentation
Provide tank steering using the stored robot configuration. Drive the robot using two joystick inputs. The Y-axis will be selected from each Joystick object.
there are more functions having same name -TankDrive- but taking different parameters so you should check it before you use it.


in the code you should call function by doing something like this
Code:
RobotDrive::TankDrive(Left,Right); //basic tank drive function under RobotDrive Class
or if you have RobotDrive type variable, you can do this also
Code:
variable->TankDrive(Left,Right);

and you can use steering wheel for controlling robot but, programming will be same since throttle stick or pedal will have/return y-axis value and the steering wheel will have/return x-axis value

Last edited by koreabell : 28-12-2008 at 20:53.
Reply With Quote
  #10   Spotlight this post!  
Unread 28-12-2008, 23:02
kyungjin kyungjin is offline
Software Specialist
AKA: Daniel
VRC #0646
Team Role: Programmer
 
Join Date: Aug 2008
Rookie Year: 2009
Location: Honolulu, Hawaii
Posts: 65
kyungjin is an unknown quantity at this point
Send a message via AIM to kyungjin Send a message via MSN to kyungjin
Re: Getting Familiar with Programming in WindRiver

Hey thanks again for the help. I really appreciate it.

I'm looking through the WPI C Programming Reference and things are slowly getting processed so that's a good thing.

I think I have an idea on how I'll implement control by steering wheel. But I have a more technical question ask you. I've noticed that the new Driver Station Unit has 4 USB ports available for use. It's it okay to plug in any USB Human Interface Device into the DSU and program or do I have to configure it? Also, is there a way to directly obtain values from the joysticks for programming use?

Thanks again for everything.
Reply With Quote
  #11   Spotlight this post!  
Unread 28-12-2008, 23:59
koreabell koreabell is offline
Team 956 Safety Captain
FRC #0956 (Eagles)
Team Role: Programmer
 
Join Date: Sep 2008
Rookie Year: 2007
Location: Oregon
Posts: 24
koreabell is an unknown quantity at this point
Re: Getting Familiar with Programming in WindRiver

When you're initializing joystick, you have to put which port the joystick is plugged in to as parameter

on the sample code you'll see this
Code:
stick = new Joystick(1); // create the joysticks
that "Joystick(1)" (which is constructor) means that it'll have control over Joystick that is plugged into port 1 on Driver Station

if for some reason it doesn't work, then it can be joystick driver software problem, which can be solved by copying driver file to USB Memory Stick(Mass Storage Device) and then plugging into driverstation.
I do not know the procedure of installing driver software since we didn't get new controller yet, but I heard that it can be done on both on-line and off-line workshops

also as I searched through some beta testing teams' codes, I found out that they were using Header & Source file for the joystick so I think it can be done via programming manually instead of installing device drivers. (I didn't analyze that files so i might be wrong but it looked like those files are in charge of joysticks teams are using)

and to obtain values from joystick, if you read Joystick class under C programming reference, there are a lot of functions like GetX, GetY, GetZ, etc

you can use that to get values of joystick axis, buttons, and stuff like that
Reply With Quote
  #12   Spotlight this post!  
Unread 29-12-2008, 03:00
kyungjin kyungjin is offline
Software Specialist
AKA: Daniel
VRC #0646
Team Role: Programmer
 
Join Date: Aug 2008
Rookie Year: 2009
Location: Honolulu, Hawaii
Posts: 65
kyungjin is an unknown quantity at this point
Send a message via AIM to kyungjin Send a message via MSN to kyungjin
Re: Getting Familiar with Programming in WindRiver

All this is very helpful information.

So, is this saying that there is a possibility of say, I plug in a random USB steering wheel into USB port 1 on the DSU, upload the driver files from a USB thumb drive (found off of the manufacturer's website) and then program using the various functions and classes using the WindRiver IDE?

Hopefully someone releases some precompiled header files so that we have steering control instead of joysticks.
Reply With Quote
  #13   Spotlight this post!  
Unread 29-12-2008, 06:05
koreabell koreabell is offline
Team 956 Safety Captain
FRC #0956 (Eagles)
Team Role: Programmer
 
Join Date: Sep 2008
Rookie Year: 2007
Location: Oregon
Posts: 24
koreabell is an unknown quantity at this point
Re: Getting Familiar with Programming in WindRiver

Quote:
Originally Posted by kyungjin View Post
So, is this saying that there is a possibility of say, I plug in a random USB steering wheel into USB port 1 on the DSU, upload the driver files from a USB thumb drive (found off of the manufacturer's website) and then program using the various functions and classes using the WindRiver IDE?
Yes, although you might not need to install device driver since steering wheel "joysticks" basically have same interface as that of normal joysticks(meaning that driverstation won't actually notice the difference between normal joysticks and steering wheel joysticks)

last year we tried to make steering wheel to drive our robot, and i remember it returning x-axis value of 127 on idle position, 0 when turning wheel all the way to left, 255 when turning wheel all the way to right or vice versa (can't remember exactly)

now, if you plug in mouse or something like that other than joystick-type HID, it'll be a different story and I'm not even sure whether it'll work or not, but as long as you plug in joystick-type HID, then you'll do fine programming

Last edited by koreabell : 29-12-2008 at 06:07.
Reply With Quote
  #14   Spotlight this post!  
Unread 29-12-2008, 07:30
JDM JDM is offline
programming lead; team executive;..
FRC #2199 (Robo-Lions)
Team Role: Programmer
 
Join Date: Feb 2008
Rookie Year: 2008
Location: Eldersburg, Maryland
Posts: 34
JDM is on a distinguished road
Re: Getting Familiar with Programming in WindRiver

Quote:
Originally Posted by kyungjin View Post
All this is very helpful information.

So, is this saying that there is a possibility of say, I plug in a random USB steering wheel into USB port 1 on the DSU, upload the driver files from a USB thumb drive (found off of the manufacturer's website) and then program using the various functions and classes using the WindRiver IDE?

Hopefully someone releases some precompiled header files so that we have steering control instead of joysticks.
That's not exactly true. Right now, the only joysticks/steering wheels/etc. that the DS supports are standard HID joystick devices that don't require drivers. There's no (published, anyway) way to get any special drivers onto the DS. (see section 3.1.8 of the control system manual or look around the beta forums)

Also, keep in mind that the Driver's Station is Linux based so if there were a way to use drivers, then they'd have to be for that platform.
Reply With Quote
  #15   Spotlight this post!  
Unread 29-12-2008, 09:10
koreabell koreabell is offline
Team 956 Safety Captain
FRC #0956 (Eagles)
Team Role: Programmer
 
Join Date: Sep 2008
Rookie Year: 2007
Location: Oregon
Posts: 24
koreabell is an unknown quantity at this point
Re: Getting Familiar with Programming in WindRiver

Quote:
Originally Posted by JDM View Post
That's not exactly true. Right now, the only joysticks/steering wheels/etc. that the DS supports are standard HID joystick devices that don't require drivers. There's no (published, anyway) way to get any special drivers onto the DS. (see section 3.1.8 of the control system manual or look around the beta forums)

Also, keep in mind that the Driver's Station is Linux based so if there were a way to use drivers, then they'd have to be for that platform.
maybe i got confused with upgrading firmware. sorry about that
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming - Getting Started Mark McLeod Programming 80 16-04-2008 23:37
Help Getting Started with VEX programming. Joe Johnson VEX 5 16-04-2007 09:01
pic: Mobot with familiar parts jgannon Extra Discussion 11 24-04-2006 18:55
programming motors with programming kit BorisTheBlade FIRST Tech Challenge 4 01-11-2005 19:03
Programming and Electronics — Getting Started Sidney San Martín Technical Discussion 7 12-01-2005 15:25


All times are GMT -5. The time now is 09:54.

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