def example(): global ids actr.reset() actr.add_command("custom-object-chunk", custom_object_chunk, "Command to dynamically create visual object") # Here we install our custom function using an object-creator device actr.install_device(["vision", "object-creator", "custom-object-chunk"]) # Now we add two features to the display, the first of which will # have the object created by the custom function and the other by # the default mechanism. ids = actr.add_visicon_features(["screen-x", 10, "screen-y", 20], ["screen-x", 100, "screen-y", 20]) # run to give vision module a chance to # process those features and then print the # visicon. actr.run_n_events(3) actr.print_visicon() # run to have model complete task actr.run(1) actr.remove_command("custom-object-chunk")
def example(): actr.reset() # The first window is located at x=0 and y=0 which # is fine for virtual windows, but if it were a real # window that window would be behind the menu bar # at the top of the display under OS X which makes # it difficult to interact with. The second window # is located at x=200, y=200. The default mouse # position is x=0, y=0. w1 = actr.open_exp_window("W1", visible=False, width=100, height=100, x=0, y=0) w2 = actr.open_exp_window("W2", visible=False, width=100, height=100, x=200, y=200) # add text to the same local position in each window. actr.add_text_to_exp_window(w1, "a", x=10, y=10, color='red') actr.add_text_to_exp_window(w2, "a", x=10, y=10, color='blue') # Install both windows and the mouse cursor actr.install_device(w1) actr.install_device(w2) actr.install_device(["vision", "cursor", "mouse"]) # Just run the model to have vision module process # things and print the visicon. # The model doesn't do anything. actr.run(1) actr.print_visicon()
def example (): actr.reset() """ We will create two items in the display and have the model find them and move the mouse to them to see the difference in timing based on the width function setting. One feature will use the normal visual-location and object chunk-types and the other will use a custom visual-location type defined like this which replaces screen-x, screen-y, and distance with slots named x, y, and z instead. (chunk-type custom-location x y z height width size) The feature with using the standard visual-location slots will include a custom width function to make it act like a circle with twice its given height. """ actr.add_command("custom-width", custom_width, "Return twice the height of a visual feature.") actr.add_visicon_features(['screen-x', 50, 'screen-y', 500, 'height', 20, 'width', 20, ':width-fn', "'custom-width'"], ['isa', 'custom-location', 'x', 150, 'y', 500, 'height', 20, 'width', 20, ':x-slot', 'x', ':y-slot', 'y', ':z-slot', 'z']) # Give the vision module a chance to process the display # before printing the visicon. actr.run_n_events(3) actr.print_visicon() # run the model to move the cursor to 100,0 as a starting point. # and from there move to the left location, back to the start, and then # the right location. actr.run(10) actr.remove_command('custom-width')
def run_test(visible=False): actr.reset() win = actr.open_exp_window("background test", visible=visible, width=390, height=390, x=100, y=100) actr.install_device(win) actr.start_hand_at_mouse() actr.add_image_to_exp_window(win, "background", "ref-brain.gif", x=0, y=0, width=390, height=390) for x in range(3): for y in range(3): actr.add_visicon_features([ "screen-x", 164 + (x * 130), "screen-y", 164 + (y * 130), "height", 128, "width", 128, "name", ["'brain'", "'brain-%d'" % (x + (y * 3))] ]) # run for the vision module to process the scene actr.run_n_events(2) actr.print_visicon() # run for up to 5 seconds using real-time if the window is visible actr.run(10, visible)
def run_test (visible=False): actr.reset() win = actr.open_exp_window("image test",visible=visible, width=310, height=420) actr.install_device(win) actr.start_hand_at_mouse() actr.add_image_to_exp_window(win, "logo", "smalllogo.gif", x=10, y=10, width=288, height=142) actr.add_items_to_exp_window(win, actr.create_image_for_exp_window(win, "brain", "ref-brain.gif", x=10, y=160, width=128, height=128, action="click-brain-py")) actr.add_image_to_exp_window(win, "brain-2", "ref-brain.gif", x=10, y=290, width=128, height=128, action=["click-brain-2-py","this string"]) # run for the vision module to process the scene actr.run_n_events(2) actr.print_visicon() # run for up to 5 seconds using real-time if the window is visible actr.run(5, visible)
def example(): actr.reset() """ Add-visicon-features returns a list of names which can be used to update the features which were added to the visicon. The modify-visicon-features command can be used to adjust the location and object representation of an item that was added to the visicon. The delete-visicon-features and delete-all-visicon-features commands can be used to remove items which were added to the visicon. For this example these chunk-types are defined in the model which subclass the standard visual-location and visual-object chunk-types as were used for the new-visicon-features example. (chunk-type (polygon-feature (:include visual-location)) regular) (chunk-type (polygon (:include visual-object)) sides) """ features = actr.add_visicon_features([ 'isa', ['polygon-feature', 'polygon' ], 'screen-x', 0, 'screen-y', 50, 'value', ('polygon', "'poly1'"), 'height', 20, 'width', 40, 'color', 'blue', 'regular', ['false', None], 'sides', [None, 7] ], [ 'isa', ['polygon-feature', 'polygon'], 'screen-x', 50, 'screen-y', 70, 'value', ['polygon', "'square'"], 'height', 30, 'width', 30, 'color', 'red', 'regular', ['true', None], 'sides', [None, 4] ]) # Give the vision module a chance to process the display # before printing the visicon. actr.run_n_events(3) actr.print_visicon() # run the model to show the current chunks actr.run(10) """ Modify the first of those features to change the color to green, adjust the x position, and change the number of sides to 8. The parameters for modify-visicon-features are very similar to add except that the list of features must start with the name of the feature to update which was returned from add-visicon-features. One thing to note is that because nil is used in the list of values to indicate that a slot should not be applied to the location or object means that you can't use nil to 'remove' a slot from a feature through a modification. """ actr.modify_visicon_features( [features[0], 'color', 'green', 'screen-x', 5, 'sides', [None, 8]]) # Give the vision module a chance to process the display # before printing the visicon. actr.run_n_events(3) actr.print_visicon() # run the model to show the update actr.run(10) # Modify the second of those features to change the regular value to false and the # height to 25 actr.modify_visicon_features( [features[1], 'height', 25, 'regular', ['false', None]]) # Give the vision module a chance to process the display # before printing the visicon. actr.run_n_events(3) actr.print_visicon() # run the model to show the update actr.run(10) # delete the second feature. delete-visicon-features takes any number # of parameters each of which should be the name of a feature that was # returned by add-visicon-feature and those features are removed from # the visicon. actr.delete_visicon_features(features[1]) # Give the vision module a chance to process the display # before printing the visicon. actr.run_n_events(3) actr.print_visicon() # run the model to show the update actr.run(10) # delete all of the visicon features. delete-all-visicon-features # removes all of the features from the visicon. actr.delete_all_visicon_features() # Give the vision module a chance to process the display # before printing the visicon. actr.run_n_events(3) actr.print_visicon() # run the model to show the update actr.run(10)
def delayed_print_visicon(): actr.print_visicon()
action=["sp-button-pressed", 0.2, "down"], height=20, width=100, color='green') actr.add_button_to_exp_window( window, text="EB", x=500, y=380, action=["sp-button-stop-pressed", 0.2, "stop"], height=20, width=100, color='red') # actr.start_hand_at_mouse() timegroup.append(t) actr.print_visicon() x = np.arange(0, 350) l1 = plt.plot(timegroup, targetgroup, 'r--', label='targetspeed') l2 = plt.plot(timegroup, actualgroup, 'g--', label='actualspeed') plt.plot(timegroup, targetgroup, 'ro-', timegroup, actualgroup, 'g+-') plt.title('Speed tracking') plt.xlabel('time') plt.ylabel('speed value') plt.legend() end_time = datetime.datetime.now() interval = (end_time - start_time).seconds print("程序共执行了:", interval) my_y_ticks = np.arange(0, 100, 0.3)
def example(): actr.reset() """ Add-visicon-features allows the modeler to specify arbirary visual features for the visicon of a model. Any number of features can be provided at once, and each feature represents an object and its location. The description of those items is provided in much the same way that one specifies a chunk i.e. as slot-value pairs, and internally the vision module uses three chunks to represent that item (the location, the object, and a feature which contains the information that can be 'found' through a visual-location request). All features must have an x and y position which default to being in the screen-x and screen-y slots (see the new-location-slots example for how to change that). The distance (z position) can be specified, but if not the default distance will be included. Similarly, a size (which is measured in degrees of visual angle squared) can be provided, but if not it will be computed from the height and width if specified or set to a default size if those are not provided. When specifying the slot-value pairs to describe a feature the slot must be a valid slot for chunks (or the name isa to declare a chunk-type). The value can be provided as either an explict value or a list of two values. If an explicit value is provided then that value represents the value of that slot for both the location and object except when it is one of the x, y, or z coordinates which are only provided in the location. If a list of values is provided then the first one represents the value of that slot for the visual-location chunk and the second one represents the value of the slot for the object. Either of the items can be specified as None to indicate that the corresponding chunk should not have that slot. The value for the feature which can be found through the visual-location request is the value for the object if one is provided otherwise it will be the value for the location. The isa specification can also take a list of two values which indicate the chunk-types to specify when creating the chunks for the location and object, which can include default slot values. In addition to that, if a chunk-type is declared for the object and no slot named kind is specified for the feature then the location chunk will include a kind slot with a value that matches the chunk-type declared for the object. For this example these chunk-types are defined in the model which subclass the standard visual-location and visual-object chunk-types. (chunk-type (polygon-feature (:include visual-location)) regular) (chunk-type (polygon (:include visual-object)) sides) (chunk-type (square (:include polygon)) (sides 4) (square t)) and the oval type is predefined by the vision module like this: (chunk-type (oval (:include visual-object)) (oval t)) One final thing to note is that if one wants to specify a string as a value for a slot it must be specified using a set of single quotes inside the double quotes of a string because when sent to ACT-R strings are interpreted as names/symbols by default for the visicon features. """ actr.add_visicon_features(['screen-x', 0, 'screen-y', 5, 'regular', 'true'], ['isa', ['visual-location', 'oval'], 'screen-x', 12, 'screen-y', 20, 'value', ['oval', "'the oval'"], 'height', 10, 'width', 40, 'color', 'blue'], ['isa', ['polygon-feature', 'polygon'], 'screen-x', 50, 'screen-y', 50, 'value', ('polygon', "'poly 1'"), 'height', 20, 'width', 40, 'color', 'blue', 'regular', ['false', None], 'sides', [None, 7]], ['isa', ['polygon-feature', 'square'], 'screen-x', 10, 'screen-y', 50, 'value', ['square', "'the square'"], 'height', 30, 'width', 30, 'color', 'red', 'regular', ['true', None], 'sides', [None, 4]], ['isa', ['polygon-feature', 'polygon'], 'screen-x', 5, 'screen-y', 70, 'value', ['polygon', "'poly 2'"], 'height', 50, 'width', 45, 'color', 'green', 'regular', ['false', None], 'sides', [None, 5]]) # Give the vision module a chance to process the display # before printing the visicon. actr.run_n_events(3) actr.print_visicon() # Then just run the model actr.run(10)
def run_experiment(start_point, end_point, verbose=True, visible=True, trace=True): """Runs an experiment""" actr.reset() # current directory actr.load_act_r_model(r"C:\Users\syl\Desktop\ACTR_ATO\sp_new_2.0.lisp") window = actr.open_exp_window("* Speed trace *", width=800, height=600, visible=visible) actr.install_device(window) # actr.add_text_to_exp_window(window, text="当前推荐速度:", x=10, y=60, height=40, width=95, color='black', font_size=22) # # actr.add_text_to_exp_window(window, text="当前速度差值:", x=10, y=20, height=40, width=180, color='black', font_size=22) # actr.add_text_to_exp_window(window, text="当前实际速度:", x=10, y=100, height=40, width=95, color='black', font_size=22) # actr.add_text_to_exp_window(window, text="距离车站位置:", x=10, y=140, height=40, width=95, color='black', font_size=22) # actr.add_text_to_exp_window(window, text="当前速度差值:", x=10, y=180, height=40, width=95, color='black', font_size=22) # actr.add_button_to_exp_window(window, text="7", x=500, y=80, action=["sp-button-pressed", 0.2, "up"], height=20, width=100, color='yellow') # actr.add_button_to_exp_window(window, text="6", x=500, y=100, action=["sp-button-pressed", 0.2, "up"],height=20, width=100, color='yellow') # actr.add_button_to_exp_window(window, text="5", x=500, y=120, action=["sp-button-pressed", 0.2, "up"], height=20, width=100, color='yellow') # actr.add_button_to_exp_window(window, text="4", x=500, y=140, action=["sp-button-pressed", 0.2, "up"], height=20, width=100, color='yellow') # actr.add_button_to_exp_window(window, text="3", x=500, y=160, action=["sp-button-pressed", 0.2, "up"], height=20, width=100, color='yellow') # actr.add_button_to_exp_window(window, text="2", x=500, y=180, action=["sp-button-pressed", 0.2, "up"], height=20, width=100, color='yellow') actr.add_button_to_exp_window( window, text="up", x=500, y=200, action=["sp-button-pressed-up-keep-down", 2, "up"], height=20, width=100, color='yellow') actr.add_button_to_exp_window( window, text="keep", x=500, y=220, action=["sp-button-pressed-up-keep-down", 0, "keep"], height=20, width=100, color='gray') actr.add_button_to_exp_window( window, text="down", x=500, y=240, action=["sp-button-pressed-up-keep-down", 2, "down"], height=20, width=100, color='green') # actr.add_button_to_exp_window(window, text="-2", x=500, y=260, action=["sp-button-pressed", 0.2, "down"], height=20, width=100, color='green') # actr.add_button_to_exp_window(window, text="-3", x=500, y=280, action=["sp-button-pressed", 0.2, "down"], height=20, width=100, color='green') # actr.add_button_to_exp_window(window, text="-4", x=500, y=300, action=["sp-button-pressed", 0.2, "down"], height=20, width=100, color='green') # actr.add_button_to_exp_window(window, text="-5", x=500, y=320, action=["sp-button-pressed", 0.2, "down"], height=20, width=100, color='green') # actr.add_button_to_exp_window(window, text="-6", x=500, y=340, action=["sp-button-pressed", 0.2, "down"], height=20, width=100, color='green') # actr.add_button_to_exp_window(window, text="-7", x=500, y=360, action=["sp-button-pressed", 0.2, "down"], height=20, width=100, color='green') # actr.add_button_to_exp_window(window, text="EB", x=500, y=380, action=["sp-button-stop-pressed", 0.2, "stop"], height=20, width=100, color='red') actr.add_command("sp-button-pressed-up-keep-down", button_pressed, "sp press button(up\keep\down) task") actr.start_hand_at_mouse() for i in range(start_point, end_point): target_speed = train_model().target_v(i) actual_speed = 10 delta_speed = actual_speed - target_speed t_group.append(i) target_group.append(target_speed) actual_group.append(actual_speed) if delta_speed > 0: delta_speed_show = "+" elif delta_speed < 0: delta_speed_show = "-" else: delta_speed_show = "0" print(i, str(int(target_speed))) deltasudu = actr.add_text_to_exp_window(window, delta_speed_show, x=550, y=180, height=40, width=95, color='red', font_size=22) # mubiaosudu = actr.add_text_to_exp_window(window, str(int(target_speed)), x=200, y=60,height=40, width=95, color='red', font_size=22) # shijisudu = actr.add_text_to_exp_window(window, str(int(actual_speed)), x=200, y=100, height=40, width=95,color='red', font_size=22) actr.run(100, True) actr.print_visicon() print( "****************************end cmd actr.print_visicon()**********************************" ) actr.all_productions() print( "****************************end cmd actr.all_productions()**********************************" ) actr.clear_buffer("visual") actr.act_r_output(actr.dm()) actr.buffer_read("manual") print( "****************************end cmd actr.buffer_read(manual)**********************************" ) # actr.remove_items_from_exp_window(window, mubiaosudu) # actr.remove_items_from_exp_window(window, shijisudu) actr.remove_items_from_exp_window(window, deltasudu) Game().draw_target_actual_speed(t_group, target_group, actual_group) actr.remove_command_monitor("output-key", "sp-key-press")