Announcement

Collapse
No announcement yet.

Using MakeCode for City Shaper!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using MakeCode for City Shaper!

    To all the teams that are planning to use https://makecode.mindstorms.com for the City Shaper, we (the MakeCode team) are listening!

    * check the https://makecode.mindstorms.com/fll page for general informations about how to use MakeCode in the FLL
    * download the offline app at https://makecode.mindstorms.com/offline-app
    * tag your forum posts with **makecode**

    Good luck on your missions!
    Last edited by pelikhan; 09-11-2019, 10:38 PM.

  • #2
    pelikhan it appears that the While loop on the MakeCode language does not work in that it doesn't loop and reevaluate the causing condition. If you open up to DM, I can give you more details. It appears from your post that you are associated with promoting MakeCode professionally. You may want to have your team revisit this.

    Comment


    • #3
      Could you share the while loop code here? You can copy paste the javascript in CODE section.

      Comment


      • #4
        .Screen Shot 2019-09-17 at 12.06.03 PM.pngScreen Shot 2019-09-17 at 12.07.04 PM.png


        Here's a While loop I just put together. By my understanding, a While loop should loop and exit when the condition is no longer met and then proceed to the next part of the program. (Please correct me if I'm wrong.) In both the simulator and the eV3, this program starts the wheels turning but they never stop, no matter if the button remains pushed or not.

        I've tried using counters and other sensors as the condition for the While loop but it never seems to complete the loop OR proceed with the remainder of the program. As I understand it, this While loop is not looping but acting as an If/Then block that doesn't end.

        Comment


        • #5
          It seems that the tight loop does not allow us to refresh the "is pressed" sensor status. I have added a short pause block in the loop to give the system a breather; and it fixes the issue. I will be looking into fixing this issue automatically.
          blocks.png

          https://makecode.com/_LM0DHHDjLRrR

          Comment


          • #6
            You can try the fix on the beta version of the editor at https://makecode.mindstorms.com/beta (v1.2.4 and up)
            Last edited by pelikhan; 09-17-2019, 05:31 PM. Reason: fixed version number

            Comment


            • #7
              What is the state of MakeCode? Is it ready to be relied on for competitions? Given errors like the above, it casts doubt that it is.

              Note that it has some appealing aspects, but I think it's unlikely that my students will switch this year, so I guess I'm asking mostly to ask.

              Comment


              • #8
                The issue above was that the while loop is running in a tight loop and preventing the threads that update the sensor status to run. So the touch button state never gets polled and you are stuck in the while loop. Typically, you would want to have a short pause in those kind of loops to allow other threads/event to run.
                We have added "contention detection" and workaround to prevent this kind of loop to starve the system.

                Comment


                • #9
                  What I can't figure out is how to get two pieces of code to run together -- for example, in Mindstorms/LabView, I could draw out and run parallel paths. I saw a "Run in Parallel" block, but it doesn't make sense how it works. Can you help?

                  Comment


                  • #10
                    Under Advanced -> Control, there is a "run in parralel" block that will start a new thread and run the code in the background. It does not merge the execution though.

                    Comment


                    • #11
                      Do you have an example of EV3 code running in parallel?

                      Comment


                      • #12
                        My kids and I worked on how to make a robot square up on a line using 2 color sensors. We had each color sensor controlling 1 motor, running at the same time. This is what we did:
                        Annotation 2019-09-18 212954.png
                        I tried to do this in MakeCode and couldn't get it to work. I tried having them run consecutively, but it doesn't really square up correctly.

                        Comment


                        • #13
                          A little more research and playing around let me do this. It's ugly, but it seems to work, at least in the simulator. Once the previous code runs, it starts two different "events", which each trigger new things to happen. Is there a cleaner, prettier way?
                          Annotation 2019-09-18 215139.png

                          Comment


                          • #14
                            I can never get the pictures to actually show up well... Here is the JavaScript.

                            brick.buttonDown.onEvent(ButtonEvent.Bumped, function () {
                            brick.setStatusLight(StatusLight.Green)
                            brick.showImage(images.eyesAwake)
                            heading = 0
                            while (sensors.color1.light(LightIntensityMode.Reflected ) >= 15 || sensors.color2.light(LightIntensityMode.Reflected) >= 15) {
                            motors.largeBC.steer(steering - sensors.gyro4.angle(), 30)
                            }
                            motors.stopAll()
                            pause(1000)
                            control.raiseEvent(
                            0,
                            0
                            )
                            control.raiseEvent(
                            0,
                            1
                            )
                            brick.setStatusLight(StatusLight.OrangePulse)
                            brick.showString("Down for line square", 10)
                            brick.showString("Up for gyro straight", 1)
                            brick.showString("Right for line following", 5)
                            })
                            control.onEvent(0, 0, function () {
                            while (sensors.color1.light(LightIntensityMode.Reflected ) <= 50) {
                            motors.largeB.run(-5)
                            }
                            motors.largeB.run(5, 30, MoveUnit.Degrees)
                            while (sensors.color1.light(LightIntensityMode.Reflected ) <= 50) {
                            motors.largeB.run(-5)
                            }
                            motors.largeB.stop()
                            })
                            control.onEvent(0, 1, function () {
                            while (sensors.color2.light(LightIntensityMode.Reflected ) <= 50) {
                            motors.largeC.run(-5)
                            }
                            motors.largeC.run(5, 30, MoveUnit.Degrees)
                            while (sensors.color2.light(LightIntensityMode.Reflected ) <= 50) {
                            motors.largeC.run(-5)
                            }
                            motors.largeC.stop()
                            })

                            Comment


                            • #15
                              Originally posted by rjbell4 View Post
                              What is the state of MakeCode? Is it ready to be relied on for competitions? Given errors like the above, it casts doubt that it is.

                              Note that it has some appealing aspects, but I think it's unlikely that my students will switch this year, so I guess I'm asking mostly to ask.
                              We are working through some issues -- getting things to work the way we were used to having them work. We are going to give it a try. I will let you know how it goes once we have some missions coded...

                              Comment

                              Working...
                              X