[solved] using joystick axis and using it's input to alter the sketchpad
Hi, I'm extremely new to opensesame, and I'm trying to make an Approach Avoidance task.
This means that I need to increase the font size (got that working) based on participant input (question 2) from the y-axis of a Logitech ATT3 (question 1).
so here are my questions:
How do I find the number for the Y-axis, and how do set this as the only correct response?
How do I set any participant input (and in this case the Y-axis) to increase/alter anything on the sketchpad?
Ive figured out how to log it, or set it as correct etc, but not how to move to a different state in a loop fashion.
Any help is appreciated!
Comments
Hi,
1 Try this script (add it to the run phase of an inline_script, placed after a joystick item) and mess about with the joystick:
It should give you the number of buttons, axes, hats and balls you have on your joystick, as well as giving you the opportunity to mess about with the joystick for 20 seconds, while showing which buttons or axes you are moving (i.e.: when you move the stick, it could read something like "joyaxes motion [0.88989 0.122332 -1]", where the changing number in between the brackets is the axis you are currently moving).
2 You should use an inline_script as above. Accessing the axes is easy if you use:
eventtype, value, time = joystick.get_joyinput()This will provide you with an eventtype (a string, which tells you what kind of input has been given (e.g. 'joybuttonpress' or 'joyaxismotion' etc.), a value for that eventtype (e.g. 4 or [0.5 0.3 -1]) and a timestamp for the input. A little sample script (for an inline_script item), for increasing a text size:
For a sample experiment (that is, this inline_script at work in an opensesame-file), see here.
Good luck!
Thank you for the clear instructions, I've started from the .opensesame file you linked and am happily coding away. sorted my error aswell. Using
t_text = exp.get("t_text")to import the not automatically available text string that is in the master loop. So now my participants (me atm) can see the stimulus text instead of something fixedHi, I'm also extremely new to opensesame, and I'm trying to make an Approach Avoidance task.
I have questions :
I'm sorry maybe it's easy questions.
All help is appreciated!
Thank you !
Hi Marie,
Welcome to the forum! Building an Approach Avoidance task is certainly possible with OpenSesame.
Did you already go through the step-by-step tutorial? I think by doing that, you'll already find an answer to the 1st and 3rd question.
Did you already try to build something yourself? And if so, where did it go wrong?
If you have any more specific questions, perhaps you could provide us with your experimental script, and we could have a closer look at it.
To upload your experiment you could do the following:
Cheers,
Lotje
Did you like my answer? Feel free to

Hi Ivanderlinden,
Thank you very much for your help.
I read the tutorial. for the question 1, I see that I can use the function .get but I don't know where I must to put it in the script.
I base on the script of Edwin (see his answer just before my question).
I try to adapt this script.
http://pastebin.com/pABPVRA1
More precisely, in the "'define inline_script inline_script", I try to put a function .get but when I run the words list don't move.
For the question 2, I would like that the initial position of words is 0. How is possible to have the coordinates of each words?
Thank you !
Hi Marie,
The tricky part in your case is to collect the joystick movement. Other than that, you probably won't need any inline coding. So let's get to the joystick part, and from there you'll probably be able to figure things out with help from the tutorial.
Basically, you want to wait until the participant pushes the joystick up or down, and then set an experimental variable (
move_joystick) to 'up' or 'down' depending on the participant's response. Once this variable has been set, you can simply use it in the OpenSesame GUI, for example in a Run-if statement that determines whichsketchpadcomes next. Again, that's all explained in the tutorials, the hard part is collecting the joystick response.So ... you can collect joystick movement with the script below. You should put this code in the run phase of an
inline_scriptthat follows the presentation of the target word. In addition, you should insert ajoystickplug-in item somewhere in your experiment, because that is needed to initialize the joystick. Even if you don't use the plug-in, it still has to be there, and you can disable it by setting its run-if statement to 'never'. Does that make sense?Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
Thank you very much for your answer.
But I need to see the size of word or picture increased when participants push and decreased when they pull.
When I try this code, I had a error message. ("Python: too many values to unpack")
I don't know where is the problem.
Thank you for your help !
The error most likely comes from this line:
As a lot of joysticks will have an output of three axes, the following line should fix this:
Alternatively, you could simply use the second axis without bothering to unpack the rest:
Regarding your original question: my sample script already increases the text on pushing, and decreases on pulling, right? If you want to apply this to a picture, you can use the
canvas' image function, which allows you to use the keyword scale.In my sample script the variable name
textsizeis used for the textsize, but you could easily do a similar thing with a variable you namepicsize. Keep in mind that this should have a lower value that the textsize, as the scale is a proportion of the original image! So you'll likely want to use values between 0.5 (half size) and 2 (twice the size).Alternatively, as Sebastiaan suggests, you could use the variable
move_joystickto change something via OpenSesame's graphical interface. E.g. using the show if statement of a sketchpad in which you have drawn a small image: show if[move_joystick] = 'down'.Does that help you at all?
Hi Edwin,
Thank you for your help. I have no error message. It's a interesting alternative. I add it in my script.
In your sample script, can you say me how and where I can import automatically a text variable that is in the precedent loop ?
I try : t_text = self.get("t_text") but It's doesn't work.
I'm too bad :-(
Thank you.
Hi Marie,
That's good news!
You are in fact using the right code, so I wonder if you are using the correct variable name and if it is defined in the preceding loop.
Example:
Define a variable called
disptextin a loop.In the sequence attached to that loop, place the sample script above.
Adjust the following line from the example:
original:
replace with:
Does that do the trick?
Hi Edwin,
Thank you so much. I had just a mistake in my script. Now it's ok.
A last question, I want to specify the joystick response (button 1) and that this response is the end of my trial.
eventtype, value, time = joystick.get_joyinput(joybuttonlist=[1], timeout=10)
But I have this message :
TypeError: argument of type 'int' is not iterable
I forget someting ?
Hi Marie,
The error suggests that the joybuttonlist is not passed as a list (i.e. in square brackets:
[1]), but rather as an integer (i.e. as a single number:1).I've checked the source code of the plug-in, and I don't see any reason for why this happens if you, as you indicate, pass the joybuttonlist as a list:
joybuttonlist=[1]. I can't test this in practice either, since I do not have a joystick around.What you could try, is an alternative approach, in which you handle the recognition of the correct button yourself. See the code snippet below for an example of what I mean.
Alternatively, the more elegant solution would be to check for both conditions at once:
Does this resolve your issue?
Hi Edwin,
I'll try and I'll let you know.
Thank you very much,
Hi, this was very helpful:
but i have problems to get my 'move_joystick' logged. logger is not working anymore.
debug windows says:
as u see i have figured out how to log time, but i want to log also variables like move_joystick, cr, fname... dont know how.
pls tell asap, thanks a lot
Best greetings
Gregor
Have you defined a variable name using only numerical values? E.g. "10".
Also, why are you using
self.login the inline_script to log a timestamp? Wouldn't it make more sense to set the timestamp as on OpenSesame variable, so that it will get picked up by the logger straight away? Like so: