Howdy, Stranger!

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

Supported by

[open] Touch input - Correct response = position of moving target

RMHRMH
edited November 2015 in OpenSesame

Hello,

I am currently in the process of putting together an experiment in Open Sesame.

It is a fairly simple display of multiple moving circles/dots. A varying number of them are distractors and two of the dots are "interacting" with each other - one is chasing the other.

We will ask participants to identify which one is the 'chaser' by touching that circle on a touch screen.

I have managed to get the display up and running using a python inline script.
I tried defining the correct response (position of chaser) in the loop item and then using a touch input item to record the response and to check whether it matches the correct response.

I can't seem to get this last part to work and am unsure if I am defining the correct response wrong in the loop item or if I would have to include correct response and commands to get the position of touch response in the inline script instead of simply using the touch input item.

I read through the information on touch input on the website but could not find anything regarding moving targets/stimuli.

I really appreciate any help you can offer!

Thank you,

Ruth

Comments

  • edited 11:33PM

    Hi Ruth,

    As far as I understand the documentation of the touch_response, you would have to divide the screen into cells that are not much larger than your stimuli in order to record correct touches on it. I don't know exactly how small the cells are, but I can imagine that there have to be quite a lot of them. Furthermore, every cell has its own identifier (a combination of row and column index), which you want to match with the current location of the moving stimuli, right? You say that you set the correct response in a loop item. That probably means that you predetermine the movement of the stimuli beforehand, in a way that you define a sequence of jumps from cell to cell. Is this the way you implemented it? If not, would you mind sharing how you did it then? In particular, I am wondering to which values you set the correct_response value in the loop.

    At any rate, for this kind of design, I would recommend using an inline_script and continuously check (from within a while loop) whether a response was given and if so, whether touch coordinates match target coordinates. But again, the exact implementation of this depends on the way you present the stimuli. If you give more details, I'll be able to help more.

    Thanks,

    Eduard

    Buy Me A Coffee

  • RMHRMH
    edited 11:33PM

    Hello Eduard,

    thank you for your reply!

    Initially, I was attempting to get it to work with the touch input but realized, after posting here, that this might be difficult as the dot getting chased (Chasee) is moving in a random rather than a predetermined pattern and the Chaser's movement is based on the position of the Chasee. So I don't necessarily know ahead of time for each trial what the position of the stimuli will be at a given time (see code below).

    I was trying to use the coordinates of the Chaser in the loop item but then noticed that that likely does not work as the touch input is using the cell grid to divide up the screen.

    Would it be easier to use a mouse element as I understand touch screens interpret touch in the same way as a mouse click and with the mouse element instead of the cells I could use the mouse's coordinates?

    I am just starting out with python so I am sorry if my questions are not very concise.
    I really appreciate any help you can offer!

    class Chasee():
        def __init__(self):
            self.x = random.randint(size, width-size)
            self.y = random.randint(size, height-size)
            self.size = 30
            self.colour = (0, 0, 0)
            self.thickness = 0
            self.speed = 0.6
            self.angle = random.uniform(0, math.pi*2)
    
        def display(self):
            pygame.draw.circle(screen, self.colour, (int(self.x), int(self.y)), self.size, self.thickness)
    
        def move(self):
            self.x += math.sin(self.angle) * self.speed
            self.y -= math.cos(self.angle) * self.speed
    
    class Chaser():
        def __init__(self):
            self.x = random.randint(size, width-size)
            self.y = random.randint(size, height-size)
            self.size = 30
            self.colour = (0, 0, 0)
            self.thickness = 0
            self.angle = random.uniform(0, math.pi*2)
    
    
        def display(self):
            pygame.draw.circle(screen, self.colour, (int(self.x), int(self.y)), self.size, self.thickness)
    
        def move(self):
            if chasee.x > self.x:
                self.x += pixChangeC
            else:
                self.x -= pixChangeC
            if chasee.y > self.y:
                self.y += pixChangeC
            else: self.y -= pixChangeC
    
  • edited 11:33PM

    Hi,

    I haven't seen many beginners in python that program in a object-oriented way. Before I get into the actual issue, first a few remarks about your code:

    1) It is possible that both chaser and chasee are initialized at the same location. I don't think you would want that.

    2) It is certainly not forbidden, but you don't need to use pygame directly. OpenSesame has canvas class, with a bunch of functions to draw circles, rectangles, etc.., independent of the back-end you are using. It might be better to use this canvas function.

    3) If the chaser is always chasing (from the first moment on), it doesn't need to have a random angle, just give it the same one as the chasee has.

    4) This is probably not all your code, but I can't see a mechanism that resolves "out-of-bounds" issues, that is what happens if the chasee is leaving the screen? Is there a reflection (adjusting the angle), or does it continue on the other side of the screen (using the modulo to adjust the coordinates)?

    Alright, now back to the actual problem. Your design is easiest to implement with a while loop, I think. So, in this loop you're continuously updating the coordinates of all stimuli on the screen. As soon as the subject is clicking on the display, you get the coordinates of the click and compare them to the current coordinates of the target. If the distance between both is smaller than a certain value (e.g., the radius of the circles), you break the loop and proceed with your experiment. Here a minimal example of the key parts of the code.


    cv = canvas() mouse = mouse() x1,y1 = current_position while True: # update circle positions x1,y1 = x1+update_factor,y1+ update_factor button, (x2, y2), timestamp = mouse.get_click(timeout= 15ms) if button !=None: if distance(x1,y1,x2,y2) < radius: break

    Does this make sense?

    Eduard

    Buy Me A Coffee

  • RMHRMH
    edited 11:33PM

    Hi Eduard,

    thank you so much for your feedback! I have been reading different ebooks and gone through tutorials that were recommended to me but am still rather new to actually writing and putting together code so I really appreciate any help and support I can get!

    I have made some adjustments based on your advice. Also, to answer your question, when the objects "hit" the boundaries of the screen, they are reflected back/bounce so they never go off screen.

    Initially, after implementing your code, I had some issues with the touch response - touch did not seem to register. I was using an older version of Open Sesame and have since updated to 3.0. Touch now registers just fine.

    I do have two more questions though:

    If I understand the code above correctly, the while loop will only break if a participant touches/clicks the chaser. This is what I want them to do but if they happened to touch a different object, I would want the experiment to move on to the next trial and just log it as an incorrect response. How would I do this?

    Also, what code/command do I have to add to the inline script so that all of the trials as listed in the open sesame loop item will be run through?

    Thank you again for taking the time to help me with this!

    Ruth

  • edited 11:33PM

    Hi Ruth,

    This code answers your first question:

    while True:
        # update circle positions
        x1,y1 = x1+update_factor,y1+ update_factor
    
        button, (x2, y2), timestamp = mouse.get_click(timeout= 15ms)
        if button !=None:
            if distance(x1,y1,x2,y2) <= radius:
                correct = True
            else:
                correct = False
            break
    
    # after having left the loop, you have to log the variables, e.g. like so:
    var.correct = correct
    

    In general, the sequence in a loop item is run exactly the number of times as you specify in the loop_table(by setting the number of cycles and repeats). So, you don't have to add anything to your inline_script to have it be run for every line in the loop_table. However, doing the reversed, that is running every line of the loop within a single inline_script is not as easy, and also not really recommended. So in short, the loop item will loop over your inline_script the number of trials times by default.

    Does this answer your question?

    Eduard

    Buy Me A Coffee

  • RMHRMH
    edited 11:33PM

    Hi Eduard,

    sorry for my delayed response - I got caught up with another project and did not get a chance to implement the new code until now.
    I have used your suggestions and code (thank you, again!) and everything seems to be working fine, except for the timeout.

    For some reason, if there is no response before the set timeout, instead of moving on to the next trial, the experiment just ends and I get the message: "Finished. The experiment finished successfully."
    If there is a response though, the experiment loops through the trials as wanted.

    Do you have any idea what might be causing this?

    Thank you very much for your time and patience!

    Ruth

  • edited 11:33PM

    Hi Ruth,

    I have to admit, I'm a bit out of the topic right now. Would you mind uploading your experiment, so that I could have a look on how you have implemented the code?
    Alternatively, you could also give some more detail on the structure of your experiment. Sorry, but I have some trouble wrapping my head around what could have gone wrong here.

    Eduard

    Buy Me A Coffee

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