View unanswered posts | View active topics It is currently Mon Aug 03, 2020 2:44 pm

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Using: TopHat
Author Message
Rookie

Joined: Thu Dec 18, 2008 4:52 pm
Posts: 5
Using: TopHat
The information given on 'TopHat' is:
 Code:joystick.joy2_TopHat; // -1 = not pressed, otherwise 0 to 7 for pressed ‘octant’

How do I write an 'if-else' code for this variable?

i.e., what I want to do is:

 Code:if (joystick.joy2_TopHat = 0) //meaning the top button of the D-pad is pressed{motor[motorD] = 50; //motor runs at 50% power}else{motor[motorD] = 0; //motor does not run}

Thu Dec 18, 2008 9:50 pm
Professor

Joined: Fri Sep 19, 2008 1:22 am
Posts: 200
Re: Using: TopHat
Here is an example from the program we wrote for the showcase tournament:

 Code:const int TopHatIdle           = -1;  // Tophat value when no button is pressed.const int TopHatNorth          =  0;  // Tophat value when the north button is pushed.const int TopHatNorthEast      =  1;  // Tophat value when the northeast button is pushed.const int TopHatEast           =  2;  // Tophat value when the east button is pushed.const int TopHatSouthEast      =  3;  // Tophat value when the southeast button is pushed.const int TopHatSouth          =  4;  // Tophat value when the south button is pushed.const int TopHatSouthWest      =  5;  // Tophat value when the southwest button is pushed.const int TopHatWest           =  6;  // Tophat value when the west button is pushed.const int TopHatNorthWest      =  7;  // Tophat value when the northwest button is pushed./**************************************************************************** HandleTopHat()** Takes the current value of the tophat control (passed in) and performs the* correct action.** In general, all tophat buttons change the behavior of the other buttons.** The North and South positions adjust the gear (speed range) of the drive motors.** The East and West positions are shift states for the 8 pushbuttons. That* means that when the tophat is pressed to the East or West no immediate* action needs to be performed. Instead, the HandleButton() code switches* on the state of the tophat to decide what mode we are in and what the* individual buttons should do.** For the purposes of this robot, if the the tophat is in the East position,* The 8 regular buttons move the sensor arm to different positions instead of* moving the manipulator arm which is the default behavior of the buttons.** Holding the tophat in the West postion is reserved for higher level behaviors* like scanning for colors, parallel parking and ordering take-out curry.*****************************************************************************/void HandleTopHat(int nTopHat){    switch (nTopHat)    {    case TopHatNorth:  // Increase the drive speed        gearup();        break;    case TopHatSouth:  // Decrease the drive speed        geardown();        break;    }}/**************************************************************************** HandleButton()** Based on the position of the tophat this function calls the corresponding* handle___Button function.** Supports 24 buttons. See the comment block for HandleTopHat for details.****************************************************************************/void HandleButton(short nButtons, short nTopHat){    if (nLastButtons == nButtons)  // If the buttons are exactly the same as they were before we're done.        return;    nLastButtons = nButtons;       // remember what buttons were pressed so we don't repeat ourselves    switch (nTopHat)    {    case TopHatEast:        HandleSensorButton(nButtons);  // Shifted button state affects sensor arm        break;    case TopHatWest:        HandleOtherButton(nButtons);   // Shifted button state does other functions        break;    default:        HandleClawButton(nButtons);    // Normal button state affects the claw arm        break;    }}

_________________
Jeff McBride
Benson Robotics Club

Fri Dec 19, 2008 12:04 am
Rookie

Joined: Thu Dec 18, 2008 4:52 pm
Posts: 5
Re: Using: TopHat
So in case of this code:

 Code:void HandleTopHat(int nTopHat){    switch (nTopHat)    {    case TopHatNorth:  // Increase the drive speed        gearup();        break;    case TopHatSouth:  // Decrease the drive speed        geardown();        break;    }}

Am I able to simply switch one of its effects with turning on a motor at some power level for instance?

i.e., instead of having 'gearup();', have like a executive command for a motor, servo, etc.

The goal is to press up and have a servo move something and and press down and have a servo move down.
I understand it would be much easier to use the other push buttons but I just want to know the possibilities available.

btw, thanks for the quick reply.

Fri Dec 19, 2008 12:19 am
Professor

Joined: Fri Sep 19, 2008 1:22 am
Posts: 200
Re: Using: TopHat
Certainly. You can make it do pretty much anything you want. I suggest that you start by writing a paragraph or two describing the behavior that you would like the tophat to have.

For example:

When the tophat is not being pressed I want the servo to stay where it is.
When the tophat is pushed north I want the servo to begin moving clockwise. It should rotate 10 degrees per second that the tophat is in the north position.
When you release the button the servo should stay put.
When the tophat is pushed south I want the servo to begin moving counter-clockwise. It should rotate 10 degrees per second that the tophat is in the south position.
When you release the button the servo should stay put.
If you press the tophat to the west the servo should immediately move all the way in the clockwise direction.
If you press the tophat to the east the servo should immediately move all the way in the counter-clockwise direction.

Once you have described your desired behavior to that level of detail then you can start creating code to implement it. You can start by turning your procedure into a big comment block at the beginning of your code.

If you can't get your code to match the behavior then you should post your code and we can give you some hints.

_________________
Jeff McBride
Benson Robotics Club

Fri Dec 19, 2008 1:30 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 4 posts ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning