{"id":10645,"date":"2015-08-06T17:44:10","date_gmt":"2015-08-06T07:44:10","guid":{"rendered":"http:\/\/legoeng.local\/?p=10645"},"modified":"2017-12-21T14:39:27","modified_gmt":"2017-12-21T03:39:27","slug":"how-to-reconnect-a-task-split","status":"publish","type":"post","link":"http:\/\/legoeng.local\/how-to-reconnect-a-task-split\/","title":{"rendered":"How to reconnect a task split"},"content":{"rendered":"

This article describes a method for “reconnecting” the separate paths of an EV3 program after a task split. It’s usually best to avoid task splits where possible, especially because of the risk of them leading to a “race condition” (more of this later in a separate post) but sometimes they’re hard to avoid.<\/p>\n

Let’s say we want to run two motors independently and then stop each one in response to a particular EV3 button. In this example, Motor A will run until the Left EV3 button is pressed and, at the same time, Motor D will run until the Right EV3 button is pressed. The task split provides a simple way of setting this up so that the motors can be turned off in either order.<\/p>\n

\"Task<\/a><\/p>\n

What if we want to continue the program after both motors have been turned off, but still allow for them to be turned off in either order? For example, how could we modify the previous example so that the cheering sound is played only after both task have completed?<\/p>\n

\"Task<\/a><\/p>\n

Maybe it would be nice if we could somehow reconnect the tasks with something like the opposite of a task split, but the EV3 Software doesn’t allow us to do that…. or at least not directly!<\/p>\n

A relatively simple workaround is to use a “flag”. That is, we create a logic variable and set it to false prior to the task split, then set it to true at the end of the forked task. Then have the main task wait until the flag is set to true before continuing.<\/p>\n

\"Task<\/a><\/p>\n

Furthermore, by creating additional logic variables to serve as additional flags and the use of a Logic Operations block in the wait loop, this idea could be extended to accommodate multiple task splits.<\/p>\n

Have fun!<\/p>\n","protected":false},"excerpt":{"rendered":"

This article describes a method for “reconnecting” the separate paths of an EV3 program after a task split. It’s usually best to avoid task splits where possible, especially because of the risk of them leading to a “race condition” (more of this later in a separate post) but sometimes they’re hard to avoid. Let’s say […]<\/p>\n","protected":false},"author":4,"featured_media":10646,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[159],"tags":[143,486,487,483,485,484],"_links":{"self":[{"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/posts\/10645"}],"collection":[{"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/comments?post=10645"}],"version-history":[{"count":0,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/posts\/10645\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/media\/10646"}],"wp:attachment":[{"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/media?parent=10645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/categories?post=10645"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/tags?post=10645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}