Go to Post I have trouble believing that there's really a regional that isn't fun... - psquared89 [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 Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 15-02-2012, 20:44
Wingy's Avatar
Wingy Wingy is offline
Team Leader
FRC #0253
Team Role: Student
 
Join Date: Jan 2012
Rookie Year: 2008
Location: Millbrae
Posts: 7
Wingy is an unknown quantity at this point
Send a message via AIM to Wingy Send a message via MSN to Wingy Send a message via Yahoo to Wingy
Joystick Buttons (or general C++ guidance)

I need guidance or an example of how to use joystick buttons to control whether a motor is on or off (the motor is being controlled by a Jaguar). I'm operating using the SimpleRobot Template. Also, although it feels strange to ask this, how do I open the GearsBot Sample code in Windriver?

Note: I'm a complete newbie. I've been trying to watch videos and understand WindRiver and the general C++ programming environment but my understanding completely halts at how to access joystick buttons as boolean for if statements. Perhaps I misunderstand C++ at it's base level, but any help would be wonderful. I am working out of the SimpleTemplate currently, but as for developing past that point I cannot seem to find where to even start on understanding it any better. I've watched http://users.wpi.edu/~bamiller/Using...iveSample.html as well as the "Intro to Workbench" video. I was hoping to go to
http://thinktank.wpi.edu/article/173 to watch the Programming 101 video, but instead I get an issue where it says the video codec is unable to be played. Considering it's a .wmv I'm really not sure why it wouldn't play.

That being said, if there are any videos explaining simple applications of C++ to FRC, that would be great. I apologize in advance for my scattered question, but at this point I'm frantic (I've been searching around threads and various forums for help for several days already).

Part of the problem is I can't deduce exactly -what- my problem is in learning C++, so please ask me questions if it'd help you to help me, or at least show me in the right direction.
Reply With Quote
  #2   Spotlight this post!  
Unread 16-02-2012, 01:11
Zero_Viscosity Zero_Viscosity is offline
Registered User
FRC #3344
 
Join Date: Feb 2012
Location: Fayetteville Georgia
Posts: 5
Zero_Viscosity is an unknown quantity at this point
Re: Joystick Buttons (or general C++ guidance)

Well, I believe that the JoyStick class has a "JoyStickButton"(or something similar) function.

There is a WPIlib documentation file which is very useful, it came with your WPIlib download.
Here is something that should make the robot drive forward for 1 second when "1" is pressed on the controller.
Code:
if(JoyStick1.RawButtonValue(1)
Drive(.5,1);
else
Drive(0.0,0.0);
Try putting that in the OperatorControl function
By the way, you would need to edit "JoyStick1" to the name of your mainstick.
If you are using SimpleTemplate and have not changed anything, it should be "stick"
Reply With Quote
  #3   Spotlight this post!  
Unread 17-02-2012, 00:10
Wingy's Avatar
Wingy Wingy is offline
Team Leader
FRC #0253
Team Role: Student
 
Join Date: Jan 2012
Rookie Year: 2008
Location: Millbrae
Posts: 7
Wingy is an unknown quantity at this point
Send a message via AIM to Wingy Send a message via MSN to Wingy Send a message via Yahoo to Wingy
Re: Joystick Buttons (or general C++ guidance)

Thanks so much, I found out the function GetRawButton(1) will get me the boolean I need. I really needed the syntax for using it as well, so thanks!

However I still have one more question: How do I use other jaguars not included in the drivetrain? How do I configure/call them and have them run?

Thanks again!

Edit: http://www.chiefdelphi.com/forums/sh...ad.php?t=99896 <--- chanced upon this thread, helped me out a bit. I had the html file but didn't know about the unblocking thing. I need to try a couple things to see if I understand it correctly, but if anyone has a straight answer for me it'd be appreciated!

Last edited by Wingy : 17-02-2012 at 00:41. Reason: New info
Reply With Quote
  #4   Spotlight this post!  
Unread 18-02-2012, 17:07
DjScribbles DjScribbles is offline
Programming Mentor
AKA: Joe S
FRC #2474 (Team Excel)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Niles MI
Posts: 284
DjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to behold
Re: Joystick Buttons (or general C++ guidance)

To use a jaguar not in the drive train you do something like this:

Code:
#include "WPILib.h"
#define AJAG_CHANNEL 1

class myRobot: public SimpleRobot
{
private:
    Jaguar aJag;
    Joystick aStick;
    myRobot():
           aJag(AJAG_CHANNEL),
           aStick(1)
    {
    }
    
    void Teleop(void) 
    {
         if(aStick.GetRawButton(4))
         {
              aJag.Set(1.0);
         }
         else
         {
              aJag.Set(0.0);
          } 
    }
}
All that should be correct and compilable but I didn't test is.

A few helpful tips:
When you have an object such as a jaguar that you want to interact with, type it's name and then a dot, then hit control + space on your keyboard. This key combo will show you a list of all things of the methods and attributes a class has (such as Set(float)), this can help you see what methods a class has for interacting with it's attributes.
(Methods are a fancy way of saying a function that a class has, and are marked with solid green dots next to them in the ctrl space popup)

Some common types of methods start with Get and Set, it's a pretty common for getters and setters to be provided for any attributes of a class that you should be able to tinker with (such as a motor's speed)

Ctrl + Space will also finish words for you, so if you name a two variables like this:
Jaguar jagWithNameSoLongItCausesCarpalTunnelSimplyToTypeI tsFullName;
Jaguar aJag;

if you type jag (Ctrl+Space) you'll see both variables popup in a window, if you type a W, the 'jagShooter' will go away, and if you hit CTRL+Space it will finish typing the whole rest of the other jagWithName...

Another great way to explore classes is to CTRL+ left click on them, if you CTRL+click aJag, you will go to where is declared, if you CTRL+click Jaguar, you will go where it is declared, which will be "Jaguar.h" which will show you this:

Code:
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.							  */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib.  */
/*----------------------------------------------------------------------------*/

#ifndef JAGUAR_H
#define JAGUAR_H

#include "SafePWM.h"
#include "SpeedController.h"
#include "PIDOutput.h"

/**
 * Luminary Micro Jaguar Speed Control
 */
class Jaguar : public SafePWM, public SpeedController, public PIDOutput
{
public:
	explicit Jaguar(UINT32 channel);
	Jaguar(UINT8 moduleNumber, UINT32 channel);
	virtual ~Jaguar();
	virtual void Set(float value, UINT8 syncGroup=0);
	virtual float Get();
	virtual void Disable();

	virtual void PIDWrite(float output);

private:
	void InitJaguar();
};

#endif
so you can see all the methods and attributes of the class.


These two things are great for getting to know what your options are in any objects in an object oriented environment!

Hope you found this helpful

Edit: Also, http://www.cplusplus.com/doc/tutorial/ is an excellent resource for learning (and for reference), it's easier to follow along than a video you gotta pause all the time (but you do have to read )

Last edited by DjScribbles : 18-02-2012 at 17:09.
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 17:39.

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