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 2019 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

    Buy Me A Coffee

  • 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


    Buy Me A Coffee

  • Hi Eduard,

    Thank you so much! It works smoothly.

    Best regards.

    Aslan

  • Hello, I tried to use the script but apparently It doesn't run because it can't read the Joystick. Do you have the same problem AslanKaraaslan?

    Thank you in advance,

    Best,

    Dam

  • Hi Dami23,


    I haven't any problem with this script. What kind of problem do you have? Can you add the opensesame error or screenshot?


    First of all, you need to put the joystick plugin anywhere in the experiment, did you?

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games