Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Joystick using for Approach - Avoidance Task

edited August 2 in OpenSesame

Hi,

I have some experience with Opensesame, but I have hardly any coding knowledge or experience. Currently, I'm trying to prepare an approach-avoidance task using the joystick (I've never used joystick before). Although I understand some of the basics of using the joystick while looking at the forum, I still need your support.

In the task, some photos will be presented, and when the participant wants to approach the photo, he/she has to pull the joystick and push forward if he/she wants to avoid it. When the participant pushes or pulls the joystick, the size of the photo should increase or decrease by 20% for every 7% of the joystick movement. When the joystick movement is greater than 30%, the stimulus screen should disappear and the fixation screen should appear.

So far I have done the following; I added a joystick plug in before a sketchpad(0 ms duration) for stimulus presentation. And after the sketchpad, in an inline_script, I added some code from the forum discussions. These codes are as follows;

# Loop until a response is given
while True:
    # Get a joystick movement
    movement,timestamp = exp.joystick.get_joyaxes()
    # `movement` is a tuple indicating the horizontal and vertical movement.
    dy = movement[1]
    # If there is vertical movement, set the variable `move_joystick` to up or
    # down, and break the loop.
    if dy < 0:
        exp.set('move_joystick', 'up')
        var.derece = dy
        break
    elif dy > 0:
        exp.set('move_joystick', 'down')
        var.derece = dy
        break

When I looked at previous discussions on this, there were some similar questions, but I did not solve some basic problems. Here my questions;

1- What can I do to increase or decrease stimulus size according to joystick movement?

2- How do I set the stimulus presentation time, based on the participant's joystick response? (Fixation screen should come when joystick movement is greater than 30% angle).

  • I guess, the solution of this is about 'while loop', but unfortunately, I have no idea how to do that.

3- I want the other buttons on the joystick to be inactive and the only allowed response is to be the joystick movement (Y axis). How can I do that?

  • I know all the button numbers except the joystick movement.

I know that the answers to these questions are available under different topics in the forum, but since I don't have coding skills, I have difficulty integrating them into this experiment. Any help would be greatly appreciated!

Kind regards,

Aslan.

Comments

  • Hi Aslan,

    1- What can I do to increase or decrease stimulus size according to joystick movement?

    In the same while loop you have to access the stimulus information and show it. For example, an image has a scale keyword that you can use, other stimuli you might have to first compute the new dimensions, and then draw it. For example:

    # preparations (can be done before the trial)
    cv = Canvas()
    cv['stim'] = Image(path_to_image.png)
    while True: 
        # do the stuff that you want to do wrt the joysticks
       # change the stimulus according to the joystick motion
        new_value = joystick_related_motion_factor
        cv['stim'].scale = new_value
        cv.show() # show the updated stimulus
    

    See https://osdoc.cogsci.nl/3.2/manual/python/canvas/ for more info

    How do I set the stimulus presentation time, based on the participant's joystick response? (Fixation screen should come when joystick movement is greater than 30% angle).

    Same way as changing the scale factor, but instead of adjusting the canvas that you are currently seeing, show another canvas that only has a fixation dot

    3- I want the other buttons on the joystick to be inactive and the only allowed response is to be the joystick movement (Y axis). How can I do that?

    I don't know whether you can actively deactive them, but if you don't access its values and they don't, per default, with your experiment, why not just ignore them?


    Hope this helps.

    Eduard

    Thanked by 1AslanKaraaslan
  • Hi Eduard,

    Thank you for your interest! And I apologize for the late reply, I was working on your suggestions during this time. And in line with your suggestions, I solved my 2nd and 3rd questions. Thank you so much!

    However, I did not figure out how to adjust the stimulus size according to the joystick movement (question 1). I'm actually using the sketchpad but these codes are about canvas. So, i couldn't adapt these codes to sketchpad. I think I need access to the sketchpad items.

    I've tried something like the following;

    cv = items['uyaranD'].canvas
    cv['stim'] = Image('[uyaranlar]')
    
    # uyaranD is my sketchpad's name,
    #'uyaranlar' is the variable which contains images in block_loop (image1.png, image2.png... etc).
    
    while True: 
        # do the stuff that you want to do wrt the joysticks
       # change the stimulus according to the joystick motion
        new_value = dy
    #dy is joystick_related_motion_factor in my experiment
        cv['stim'].scale = new_value
        cv.show() # show the updated stimulus
    


    But it doesn't work:(.

    I receive the error message "The picture file '[uyaranlar]' does not exist."

    I don't understand what to write instead of "image (path_to_image.png)".

    Any suggestions would be appreciated!

    Thanks in advance.

  • I've tired to new way as below:

    stop = False
    cv = items['uyaranD'].canvas
    #cv['stim'] = Image('[uyaranlar]')
    
    
    # Loop until a response is given
    while not stop:
        # Get a joystick movement
    	movement,timestamp = exp.joystick.get_joyaxes()
        # `movement` is a tuple indicating the horizontal and vertical movement.
    	dy = movement[1]
    	
    	 # If there is vertical movement, set the variable `move_joystick` to up or
        # down, and break the loop.
    	if dy < 0:
    		new_value = dy
    		cv[var.uyaranlar].scale -= new_value
    		cv.show() 
    	elif dy <= -0.99:
    		exp.set('move_joystick', 'up')
    		var.derece = dy
    		stop=True
    		break
    	if dy > 0:
    		new_value = dy
    		cv[var.uyaranlar].scale += new_value
    		cv.show()
    	elif dy >= 0.99:
    		exp.set('move_joystick', 'down')
    		var.derece = dy
    		stop=True
    		break
    
    

    Now, i have a KeyError u problem with the name of image file.

    Details


    item-stack: experiment[run].practice[run].new_sequence[run].new_inline_script_3[run]

    exception type: KeyError

    exception message: u'0299.jpg'

    item: new_inline_script_3

    time: Sun Aug 25 14:43:47 2019

    phase: run

    Even if there is no Turkish or special characters in the image file name, this error message occurs.

    Thanks.

  • I still haven't solved the problem. I've attached the experiment file (a draft) below.

    Any suggestions will make me grateful to you.


  • HI Aslan,


    Sorry for the late reply. I changed a bit of the code. The main problem was that the image in the sketchpad was not found. This should be fixed now. However, I don't have a joystick to test whether the experiment does what it is supposed to. Could you confirm?

    Eduard


  • Hi Eduard,

    Thank you so much! It works smoothly.

    Best regards.

    Aslan

Sign In or Register to comment.