View unanswered posts | View active topics It is currently Fri Aug 01, 2014 1:03 am






Reply to topic  [ 12 posts ] 
Joystick.joy1_buttons & joystick.joy1_TopHat problems 
Author Message
Rookie

Joined: Sat Nov 03, 2012 4:47 pm
Posts: 4
Post Joystick.joy1_buttons & joystick.joy1_TopHat problems
Hi,

We are facing a problem with the joystick (ours is the Logitech Gamepad F310 with the color buttons X, A, B, Y
instead of 1, 2, 3 & 4). The mode is off & behind, the tab is on 'D' side.

The joystick.joy1_TopHat & joystick.joy1_Buttons are always showing values '0' & '0' no matter which button is pressed or not when in debug mode
using joystickcontrol-competition.
The joystick debug window shows the correct buttons pressed & their correct values like 00, 01, etc. I am not sure why.

Since the program is in a loop & it gets the joystick values everytime, joystick.joy1_Buttons should correspond to 1, 2, 4, 8 & so on
for buttons 00, 01, 02, 03, etc. But is is always 0. Same thing is happening with joystick.joy1_TopHat - it is always showing 0
while it is supposed to be -1 when not used. Like I said, the joystick window shows the correct values but not the debugger window.


The same test program works on the another team's PC which beats me! We bot have the same version of RobotC but I suspect they dont have
VW installed but I do. Not sure what to do. Incidentally, this was working yesterday night...I have noticed this behavior that sometimes
things work & sometimes, the same code does not. Restarting my laptop sometimes has helped but it did not help me today.
I uninstalled & reinstalled RobotC 3.51 without the virtual world. I am still having the same problem. Below is the code....I would greatly
appreciate if someone could shed some light on this. We are supposed to have this ready by today but it looks impossible.

The code below is a very simple teleop which just plays tones depending upon the button pressed and write strings to the debugger window:

#pragma config(Hubs, S1, HTMotor, none, none, none)
#pragma config(Hubs, S2, HTMotor, none, none, none)
#pragma config(Hubs, S3, HTMotor, none, none, none)
#pragma config(Hubs, S4, HTServo, none, none, none)
#pragma config(Sensor, S1, , sensorI2CMuxController)
#pragma config(Sensor, S2, , sensorI2CMuxController)
#pragma config(Sensor, S3, , sensorI2CMuxController)
#pragma config(Sensor, S4, , sensorI2CMuxController)
#pragma config(Motor, motorA, Grab, tmotorNXT, PIDControl, encoder)
#pragma config(Motor, mtr_S1_C1_1, DR, tmotorTetrix, openLoop, reversed)
#pragma config(Motor, mtr_S1_C1_2, DL, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S2_C1_1, LiftA, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S2_C1_2, LiftB, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S3_C1_1, Arm, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S3_C1_2, motorI, tmotorTetrix, openLoop)
#pragma config(Servo, srvo_S4_C1_1, RingPusher, tServoNone)
#pragma config(Servo, srvo_S4_C1_2, servo2, tServoNone)
#pragma config(Servo, srvo_S4_C1_3, servo3, tServoNone)
#pragma config(Servo, srvo_S4_C1_4, servo4, tServoNone)
#pragma config(Servo, srvo_S4_C1_5, servo5, tServoNone)
#pragma config(Servo, srvo_S4_C1_6, servo6, tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

// #Defines
// Macro To Scale JoyStick Value to match Motor Value Joy -128 to 127 vs. Motor -100 to 100
#define MOTORSCALE(X) ( ( ( X ) * 100) / 127 )



//Motor and Sensor Configuration

#include "JoystickDriver.c" //Joystick's In Program

short joy1BtnMod(int btn)
{
short joytemp = joystick.joy1_Buttons;
if ( (joytemp & (1 << (btn))) != 0)
{
return 1;
}
return 0;
}

short joy2BtnMod(int btn)
{
short joytemp = joystick.joy2_Buttons;
if ( (joytemp & (1 << (btn))) != 0)
{
return 1;
}
return 0;
}


task main()
{
short threshold = 15; // Avoids Twitching


while(1)
{
int count;
getJoystickSettings(joystick); // Gets Joystick
/* Debug Code
short joy1_Btns;
short joy1_return;
joy1_Btns = joystick.joy1_Buttons;
joy1_return = joy1BtnMod(0);
joy1_return = joy1BtnMod(1);
joy1_return = joy1BtnMod(6);
*/ // End Debug Code

// Buttons 00 to 11
for (count=0;count < 12 ;count++)
{
if (joy1BtnMod(count))
{
PlayImmediateTone(200 + (count * 50), 1);
writeDebugStreamLine("Button # %d was pressed ", count);
}
} // End For

// Top Hat
if ( joystick.joy1_TopHat != -1 )
{
PlayImmediateTone(1000 + ( joystick.joy1_TopHat * 50), 1);
writeDebugStreamLine("Top Hat # %d was pressed ", joystick.joy1_TopHat);
}
// X Value

if(abs(MOTORSCALE(joystick.joy1_x1)) > threshold)
{
PlayImmediateTone(1000 + ( MOTORSCALE(joystick.joy1_x1) * 3), 1);
}
else
{
motor[DR] = 0; // Says if you have joystick Forward it'll go forward same as back for right druve wheel
}

if(abs(MOTORSCALE(joystick.joy1_x2)) > threshold)
{
PlayImmediateTone(500 + ( MOTORSCALE(joystick.joy1_x2) * 3), 1);
}
else
{
motor[DL] = 0; // Says if you have joystick Forward it'll go forward same as back for left drive wheel
}


// Y Values
if(abs(MOTORSCALE(joystick.joy1_y1)) > threshold)
{
PlayImmediateTone(700 + ( MOTORSCALE(joystick.joy1_y1) * 3), 1);
}
else
{
motor[DR] = 0; // Says if you have joystick Forward it'll go forward same as back for right druve wheel
}

if(abs(MOTORSCALE(joystick.joy1_y2)) > threshold)
{
PlayImmediateTone(700 + ( MOTORSCALE(joystick.joy1_y2) * 3), 1);
}
else
{
motor[DL] = 0; // Says if you have joystick Forward it'll go forward same as back for left drive wheel
}




} // End While 1

} // End Main


Thanks,
NerdBots


Sat Nov 03, 2012 4:56 pm
Profile
Rookie

Joined: Sat Nov 03, 2012 4:47 pm
Posts: 4
Post Re: Joystick.joy1_buttons & joystick.joy1_TopHat problems
Hi,

I just tried a very simple program but again nothing happens when I push any of the buttons (Especially button1). Any comments/suggestions would be great!

#pragma config(Hubs, S1, HTMotor, HTServo, none, none)
#pragma config(Motor, mtr_S1_C1_1, motorD, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C1_2, motorE, tmotorNormal, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/*--------------------------------------------------------------------------------------------------------*\
|* *|
|* - Tetrix Quiet Tank Drive - *|
|* ROBOTC on Tetrix *|
|* *|
|* This program allows you to drive a robot via remote control using the ROBOTC Debugger. *|
|* This particular method uses "Tank Drive" where each side is controlled individually like a tank. *|
|* This program also ignores low values that would cause your robot to move when the joysticks fail to *|
|* return back to exact center. You may need to play with the 'threshold' value to get it just right. *|
|* *|
|* ROBOT CONFIGURATION *|
|* NOTES: *|
|* *|
|* MOTORS & SENSORS: *|
|* [I/O Port] [Name] [Type] [Description] *|
|* Port D motorD 12V Right motor *|
|* Port E motorE 12V Left motor *|
\*---------------------------------------------------------------------------------------------------4246-*/

#include "JoystickDriver.c"

task main()
{
int threshold = 10; /* Int 'threshold' will allow us to ignore low */
/* readings that keep our robot in perpetual motion. */

while(true) // Infinite loop:
{
getJoystickSettings(joystick);

// BUTTONS TO CONTOL SERVO ARM
// Control arm via shoulder buttons, 5 and 6... 5=up, 6=down

if(joy1Btn(1)) // If Button 5 is pressed:
{
PlayImmediateTone(200 + (1 * 50), 1);
writeDebugStreamLine("Button # %d was pressed ", 1);
}
}
}


Sat Nov 03, 2012 5:45 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Joystick.joy1_buttons & joystick.joy1_TopHat problems
Just a suggestion, do you know you can daisy chain the four motor controllers on one sensor port instead of using all four sensor ports? That way you will have extra ports for sensors and other things.
Regarding the button code, I have noticed a few things that may or may not be related to your problem. You may want to fix them and see if it improves things.
1. Your main robot loop has no "wait1Msec()" statement, meaning that your loop is a very tight loop running as fast as it could. This may not be desirable because it may starve other background task that RobotC has running (e.g. the task that update the joystick values).
2. You are outputting debug text to the debug stream in a tight loop. It means your connection to the robot is probably overwhelmed with these debug messages. Your PC is using the same connection to transmit joystick messages to the robot. I recommend you use the NXT LCD display to do your debugging instead of using debug stream.
Another suggestion is to simplify your test program to test one thing at a time. For example, the following code will only test the joystick buttons. If that works, then you can add more code.
Code:
#include "JoystickDriver.c"

task main()
{
    while(1)
    {
        getJoystickSettings(joystick); // Gets Joystick
        nxtDisplayTextLine(0, "J1Btns=0x%02x", joystick.joy1_Buttons);
        nxtDisplayTextLine(1, "J1TopHat=%d", joystick.joy1_TopHat);
        wait1Msec(50);
    } // End While 1
} // End Main


Sat Nov 03, 2012 5:52 pm
Profile
Rookie

Joined: Sat Nov 03, 2012 4:47 pm
Posts: 4
Post Re: Joystick.joy1_buttons & joystick.joy1_TopHat problems
Hi MHTS,

Thanks for your suggestions. We first tried daisy chaining but certain components of the robot were not working that way & we couldn't figure out why & were pressed for time:-); hence using multiple ports/controllers.

We tried the simpler code that I posted in the second post in this thread which is like bare bones and that doesn't work.

I tried the code you had suggested and this is what we saw in the NXT brick:

J1Btns=0x00
J1TopHat=0


:-( Not sure why... Are there any specific settings to be set in RobotC? I tried on a different laptop with 3.51 but no luck too.

Thanks


Sat Nov 03, 2012 7:20 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Joystick.joy1_buttons & joystick.joy1_TopHat problems
When you pressed the buttons, did you see the corresponding buttons on the joystick dialog responded? If it did, your PC was recognizing button activities. What version of RobotC are you using? There were a lot of issues with RobotC even with 3.51. The latest beta fixed all the known issues which is due anytime now. But looking back at all the bug reports, I don't see any issues with Joystick, so I don't know what your issue is. If TopHat is 0, something is not quite right. It should be -1 if nothing is pressed. What is the communication link between the brick and your PC? Is it USB, Bluetooth or WiFi? You may want to try other communication link. But since you can download code and all, it should be fine. I am running out of ideas what could be the issue.


Sun Nov 04, 2012 1:32 am
Profile
Rookie

Joined: Sat Nov 03, 2012 4:47 pm
Posts: 4
Post Re: Joystick.joy1_buttons & joystick.joy1_TopHat problems
Hi MHTS,

Thanks for your reply. Please see my replies to you..

When you pressed the buttons, did you see the corresponding buttons on the joystick dialog responded? Yes, when button 1 was pressed it showed '00' on the Joystick dialog; button 2 showed '01' and no buttons shows blank. Similarly, with the tophat, it showed -1 when not pressed and the respective 0-7 values for the tophat when pressed.

If it did, your PC was recognizing button activities. What version of RobotC are you using? 3.51-I uninstalled & reinstalled to just make sure.

There were a lot of issues with RobotC even with 3.51. The latest beta fixed all the known issues which is due anytime now. I just noticed that 3.54 is out...is it safe to install it now or should I wait?

But looking back at all the bug reports, I don't see any issues with Joystick, so I don't know what your issue is. If TopHat is 0, something is not quite right. It should be -1 if nothing is pressed. What is the communication link between the brick and your PC? Is it USB, Bluetooth or WiFi? USB

You may want to try other communication link. But since you can download code and all, it should be fine. I am running out of ideas what could be the issue.
I hope others give their suggestions too...Our qualifiers are on Nov. 10th in less than a week and we are unable to proceed further due to this joystick problem:-( :-(

Thanks


Sun Nov 04, 2012 11:44 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Joystick.joy1_buttons & joystick.joy1_TopHat problems
NerdBots wrote:
I just noticed that 3.54 is out...is it safe to install it now or should I wait?

Yes, it is safe. I have been testing 3.54 for a while now. Give it a try and let me know if it solves your problem.


Sun Nov 04, 2012 1:28 pm
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 601
Post Re: Joystick.joy1_buttons & joystick.joy1_TopHat problems
ROBOTC uses the same DirectX input as other Joystick-supported applications. Can you try using Windows joystick configuration utility in Control panel to see if its reporting as correct?

Also, do you have any other applications that may be "hijacking" the joystick data that may not be installed on the other laptop you tried?

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net


Mon Nov 05, 2012 9:41 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Joystick.joy1_buttons & joystick.joy1_TopHat problems
Since the "joystick dialog" in RobotC is responding to button and joystick events, I would expect it is not a problem with DirectX joystick support. So the next component in the pipe would be the communication link between the PC and the NXT. But if he can download code to the NXT, I wouldn't think the link is an issue either. Unless some of the information was wrong, I am running out of ideas on why it doesn't work. He also said the same code worked on another team's PC. So the code was not the culprit either.


Tue Nov 06, 2012 2:57 am
Profile
Rookie

Joined: Mon Nov 12, 2012 3:39 pm
Posts: 2
Post Re: Joystick.joy1_buttons & joystick.joy1_TopHat problems
Hi - we are a rookie team, and also having strange issues with Logitech F310 w/ USB connection. Using v 3.54, the basic ranger robot configuration and the example L2_joystickControl.c sample program- left controller on logitech works fine- values display in joystick dialog go from -128 to +128 down/up, motor turns....but right controller values do not change at all (and motor also does not move).

Have re-booted, tried another F310, restarted NXT, etc.

Any thoughts on how to debug? Is this a known issue, or a new one? Thanks-


Mon Nov 12, 2012 3:54 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 558
Post Re: Joystick.joy1_buttons & joystick.joy1_TopHat problems
motorbolts wrote:
Hi - we are a rookie team, and also having strange issues with Logitech F310 w/ USB connection. Using v 3.54, the basic ranger robot configuration and the example L2_joystickControl.c sample program- left controller on logitech works fine- values display in joystick dialog go from -128 to +128 down/up, motor turns....but right controller values do not change at all (and motor also does not move).

Have re-booted, tried another F310, restarted NXT, etc.

Any thoughts on how to debug? Is this a known issue, or a new one? Thanks-


There are two things you will need to check; make sure the switch on the back of the controller is set to "D" (for digital mode) and not "X" (for Xbox mode), and that the 'Mode' light on the front is turned off (there is a mode button you will have to press if it's on).

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Mon Nov 12, 2012 4:01 pm
Profile
Rookie

Joined: Mon Nov 12, 2012 3:39 pm
Posts: 2
Post Re: Joystick.joy1_buttons & joystick.joy1_TopHat problems
Thanks for the quick response- unfortunately we had tried those 2 things already - the F310 is set to "D" not X, and the mode light is off. We had tried toggling through both of those settings on the remote control in our troubleshooting.

Seemed quite odd that one joystick worked fine, and the other one not at all. We reversed the motor connections and the same
Left joystick still worked, just controlled the opposite motor. Both F310's that came in the kit have the same issue.

Any other tricks to try?


Mon Nov 12, 2012 4:55 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 12 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.