Anyone having problems with ModKit.?
Sometimes the program works fully, then other times
“Broadcasts” are not even recognized, even when it is the last line of code.
E.g. Raise the top of the claw when facing the high goal.
We have “Broadcast” called “Claw open” and the broadcast works perfectly when we start the program to open the claw
and raise the lift to grab 2 balls off the fence, so why wouldn’t the “Broadcast” work any where else in the code?
It is not stuck in a loop to keep the claw down.
Do you need to use “hold power” off immediately after the “When Claw open”, so it is released it? Maybe the answer since when the bot stops after the
“Broadcast Claw open” there is massive hold power still from the “Broadcast Claw down”. Hmm
Will try that to see.
Anyone having problems with ModKit.?
Can you please post the code with the “unheard” broadcast?
Meanwhile, a bit on broadcasts vs. variables:
I have found that broadcasts, especially from the brain to a series of motors, are not always “heard” at the same time. For example, I created a simple code in which multiple motors were all to run for 3 seconds and then to pause for 1 second. I used broadcast and had the brain send out commands to either “run” or “wait.” I looped this code 5 times. By the end of five iterations, the motors were noticeably out of sync.
However, when I used a “run” variable and had the brain simply switch the variable from 1 to 0 (with associated wait times) and looped this five times, they were spot on. The motors simply “listened” from inside their own forever loops for the variable to change. If variable = 1, run; else stop. Simple and reliable. Of course, only a simple program, but it clearly demonstrated to my students the power of variables. And because variables can be assigned new values from anywhere in the code, none of my students use broadcasts anymore!
Here’s the code. Pretty straight forward.
Where can we get more tutorial on the Variable use?
Thanks. I volunteer on Thursdays, so I’ll have time tomorrow to post more info and a sample program using a variable. Not hard to use
Please review the info below on creating a variable and post me back if you have any questions.
Also, if you would like me to troubleshoot the code you posted yesterday, please provide more screenshots of the rest of the code so that I can see when and where the broadcasts are initiated. (If this is just taken from the standard drive train or controller code provided in modkit, let me know that as well - I’m not sure about this because I always write my own code Thanks!
To create a variable:
Click on “New Variable” in the block list. [see photo 1]
Next is sample code for a simple challenge we call “A Hobbit’s Tale” (a.k.a. “There and Back Again”
This is one of the first autonomous challenges that I give students. I create two tape squares on the floor about 6-8 feet apart. Each square is large enough for the entire clawbot to fit inside AND turn around – approximately 18 inches square.
I included a quick line drawing of this setup. [see photo 2]
The goal is simple.
- drive from ENTIRELY inside one box to the other,
- turn around ENTIRELY inside the second box,
- drive back, and
- stop ENTIRELY inside the first box.
This sounds really easy to students, but they soon realize it’s quite an exacting task. They will get close several times without quite succeeding. I also require them to be able to repeat it – luck should not be a factor!
Some common causes for failure:
- tires are poorly mounted on the wheel hubs, causing imbalanced tires and irregular movement
- broadcasts aren’t initiated for both motors simultaneously
- timings or motor rotations are off – even slightly (Note: Rotations are more precise than timing, but timing is easier for students to understand when we are first starting out.)
- faulty logic / programming (happens a lot when we first get started!)
First I assign the variable and have it change after a specific period of time. [brain code]
Note that the left motor always turns forward… [left motor code]
…while the right motor reverses direction whenever the variable is equal to 2. [right motor code]
SO… When the motors are both turning forward (switch = 1), the bot goes straight forward. When the motors are turning in opposite directions (switch = 2), the bot turns in place. When switch is 0, the motors stop.
In addition to using time intervals, variables can also be set / reset whenever a button is pressed on the remote, when a bump switch is touched (for example, when the claw is lowered all the way down), a task is completed, the color sensor value detects red for color OR is equal or greater to a certain number using the ambient light setting, and on and on! The numeric value for the variable can also be used in mathematical operations: [variable = variable +1, for example], or logic statements: [IF variable is >5…, ELSE…]
I think you will find many uses for variables, and the BEST part is that you only have to set them in ONE line of code to simultaneously affect multiple motors or logic statements throughout your entire code.
I’m sending some screem shots of our code. I appologize they are out of order. The drive train was too long to put on 1 screen shot.
Here are the next 3
Hello again, Osteocoach~
Had a bit of time this afternoon, and I was about to recreate your code when I really “looked” at the screenshots. It appears that you have when statements that are based on variables.
Your R. Touch led has a when for GyroAGo, but there is no broadcast for this. (This is a variable assigned to equal 1 by your gyro after it calibrates and resets its rotation. Without a matching broadcast of GyroAGo, there is no signal for your led to “hear.” In the same led code you also set a variable called startmoving to 1, which your drivetrain listens for, in the form of another when…
So, to clarify, variables do not behave the same as broadcasts. To activate a when, you need a matching broadcast. To use a variable change, such as GyroAGo, to activate another bit of code, you need a different set of ears to listen for this. Try a “when start” and a forever loop (else it will only check this code once at startup, and if the condition fails, will not run this code again). Inside the forever loop, put an if statement that says, if GyroAGo = 1… and place your code inside of this if loop.
At the end of this bit of code, either in or outside the if statement, you need to reassign GyroAGo to a different value, such as 0. This reassignment essentially says, “I’m done,” else the forever loop will restart (variable still =1)
This is where the new value, or a different variable can be used to activate the next bit of code. This could be your startmoving variable. Simply create a new forever loop in the drivetrain that watches for his variable change to initiate its code. Of course, the drive train could simply listen for the GyroAGo variable to be assigned a value of 2. This is the method I prefer. By using the same variable, when possible, you can end one loop and initiate the next simultaneously.
Either way, what’s cool about broadcast or variable change triggers is that you can write specific bits of code to turn, close the claw, lift the arm, etc. Place each set of instructions inside a when (broadcasts) or a forever / if loop (variable change), and you can use these over and over in a continuous chain of events without duplicating the same instructions for repetitive events. You can also test segments of your code independently, which saves time.
Please try one combination of triggers/listeners described above. If you are still not getting all of your code to execute, I would suggest adding your led into the mix. I teach my students to use forever loops and variable changes, but when they are having problems, I have them program their leds to listen to the same variable and to change color for each newly assigned value. That way, they can “see” which loops of their code are being triggered and which are not simply by noting which colors they see
Best of luck!