Howdy, Stranger!

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

Supported by

[solved] Touch Screen Corsi Task - Borrowing a little code!!

edited April 2014 in OpenSesame

Hi I have recently begun my PhD and I'm quite new to programming / code etc. I used the below piece of code which I found in another stream as I am developing what I hope will be a touch screen Corsi task. In this participants are required to watch a block sequence and then tap this out on screen in the same order. Sequence lengths vary from 2 to 9. I'm doing it forwards and then backwards, harder than it sounds believe me.
Therefore I need opensesame to regcognise a touch response within the square and not anywhere else on screen and then log the co-ordinate of the touch. To be more specific I need it to do this for each tough, so if the sequence is 5 blocks long, I need SPSS to record 5 taps, whether correct / incorrect and coordinates. I also want reaction time but I'm not sure if this is a later question I might have to post. I used the below code therefore and I think I have it working, of sorts, but I was just wondering if anyone knew, for write up / understanding purposes how exactly the code calculates acceptable distance, how far is too far in essense from the square to be considered correct? I'm sorry if this is completely out of context from the original post as well, I'm relatively new to forums also.

Thank you , Katherine.

from math import sqrt
# The maximum error from the target center
maxClickErr = 100
# Use Pythagoras to determine the click error and set
# the variable `correct` to 1 (correct) or 0 (incorrect)
# depending on whether the click error is small enough.
# Because the cursor coordinates have 0,0 at the top-left
# and the sketchpad coordinates have 0,0 at the center,
# we need to compensate for the display size.
xc = self.get('width') / 2
yc = self.get('height') / 2
# Determine x and y error
dx = self.get('cursor_x')- xc - self.get('xTarget')
dy = self.get('cursor_y')- yc - self.get('yTarget')
# Determine error
clickErr = sqrt(dx**2 + dy**2)
# Determine `correct` variable
if clickErr <= maxClickErr:
    exp.set('correct', 1)
else:
    exp.set('correct', 0)

Comments

  • edited 8:59AM

    Hi Katherine,

    Welcome to the forum!

    The variable maxClickErr in this script indicates the maximum distance in pixels that a touch can be from a specific target point, indicated by xTarget and yTarget. So the acceptable area is a circle around the target point with a radius of maxClickErr pixels.

    Does that answer your question?

    Cheers,
    Sebastiaan

  • edited 8:59AM

    Thank you, yes of sorts, I think my problem is that I've used this code thinking it would be appropriate for my task. Basically the corsi blocks task uses squares as targets. To this extent I've used the above code so that now it draws an acceptable target circle around the square which is largely fine as the margin for error is so small outside of the target, but is there a way that I could adapt the above code specifically for squares?

    Thank you,
    Katherine.

  • edited April 2014

    Hi Katherina,

    Sure, the dx and dy variables indicate respectively the horizontal and vertical deviation from the target center. So defining an acceptable square would be something like this:

    Update: Corrected script

    # Determine `correct` variable
    if clickErr >= abs(dx) and clickErr >= abs(dy):
        exp.set('correct', 1)
    else:
        exp.set('correct', 0)
    

    Cheers,
    Sebastiaan

  • edited 8:59AM

    Hi Sebastiann,

    thank you for your help so far. I now might need a little more though, I've changed my design slightly so that it uses rectangles as stimuli which are 151 x 117 pixels in size and like before I need them to be targets for the touchscreen version. I'm currently trying to adapt the first piece of code on this thread to use rectangles, trying to work it out considering that you explained how I would make it relevant for squares. However I am yet as able to do that. I was wondering if you would be able to give me the full code for using rectangles as targets? Would I need to remove the square root part of the original code in this thread?

    Sorry,

    Thank you,
    Katherine x

  • edited April 2014

    Hi Katherine,

    I now notice that there is a mistake in my previous post. You should not compare clickErr against the horizontal (dx) and vertical (dy) deviation, but maxClickErr. And if you want to use a rectangle instead of a square, you need to use different maximum errors for the horizontal and vertical. For example like so:

    Update: Corrected script

    from math import sqrt
    # The maximum error from the target center
    maxClickErrX = 115/2
    maxClickErrY = 117/2
    # Use Pythagoras to determine the click error and set
    # the variable `correct` to 1 (correct) or 0 (incorrect)
    # depending on whether the click error is small enough.
    # Because the cursor coordinates have 0,0 at the top-left
    # and the sketchpad coordinates have 0,0 at the center,
    # we need to compensate for the display size.
    xc = self.get('width') / 2
    yc = self.get('height') / 2
    # Determine x and y error
    dx = self.get('cursor_x')- xc - self.get('xTarget')
    dy = self.get('cursor_y')- yc - self.get('yTarget')
    # Determine `correct` variable
    if maxClickErrX >= abs(dx) and maxClickErrY >= abs(dy):
        exp.set('correct', 1)
    else:
        exp.set('correct', 0)
    

    So you basically just check if the horizontal and vertical deviation are smaller than or equal to the maximum click error. Pretty straightforward, really. Does that make sense?

    Cheers,
    Sebastiaan

  • edited 8:59AM

    Hi Sebastiaan,

    thank you for your help, I pasted that code in t replace what I had before and changed the 115 to 151 because that's the width of my rectangle, but it now isn't registering any clicks as correct at all. I'm not sure why. No matter how close to the centre the results just keep registering 0 correct. I will continue to have a look at this, any ideas though?

    Thank you again for your help,
    Katherine.

  • edited 8:59AM

    Also what does abs stand for? The rest I think I understand. Thank you, Katherine.

  • edited 8:59AM

    Wait I think I may have done it, the arrows should be the other way around? >=abs(dx)?

    thankyou

  • edited 8:59AM

    Hi Katherine,

    The function abs() is to calculate the absolute value of a number. This is defined as the square root of the square of the original number, which basically comes down to the same number as you put in, but without the minus sign. Examples: abs(3) == 3, and abs(-3) == 3.

    It seems the "smaller than or equal" sign should have indeed been a "greater than or equal". Sorry about that!

  • edited 8:59AM

    It seems the "smaller than or equal" sign should have indeed been a "greater than or equal". Sorry about that!

    Oops 8-}

  • edited 8:59AM

    Its o.k, thank you both lots, you've been a massive help and I think I'm one step closer now to understanding programming, she sais :/ . . I think I finally have my Corsi task up and running though, stopping rule and touch screen response working, thank you. I will spread the word!!!!

    thanks, kat x

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