Closed ghost closed 4 years ago
FYI, SD cards > 32GB are not supported.
It looks like you are creating a new LargeMotor
object each time you call the function. This should only be done once per program per motor.
Thank you!
That makes perfect sense, seeing where it is bombing.
Should I have the kids add that to the robot state initialization function they have that sets up the robot's initial position and orientation or at the beginning of the module/main program?
Does the same proscription against multiple calls of the LargeMotor apply to the MoveSteering command, also?
The kids are using the MoveSteering to drive the motors, but needed to get the position and speed of each motor to check the robot's travel distance, and used the LargeMotor object to access that data.
Re: the SD Card - it is 32GB.
Thanks again!
The idea is just that you should use a long-lived instance for things like motors and Drive objects. Setting up a Motor is slow, so you should do it once then use it for the duration.
Would the same advice apply to sensors?
Yes. Pretty much every class in this library, when initialized, has to do some file I/O to prepare to talk to the device it's supposed to interact with. They aren't designed to be rapidly created or have lots of them in memory at once.
I just tested it. Worked like a charm. I think I know how to explain it to them when we meet next.
I declared the MoveSteering and 2 LargeMotor objects at the beginning of the module and passed them into the Forward function, e.g.:
Forward(Speed, Distance, Ramp_Up, Ramp_Down, Brake_On, State, DriveMotors, LeftMotor, RightMotor)
But then I tested instantiating the LargeMotors and MoveSteering and didn't pass them in"
Forward(Speed, Distance, Ramp_Up, Ramp_Down, Brake_On, State)
And it still worked - so I guess they are global in scope.
Method 2 is less complicated - I suppose we'll go with that, although my kids will give me back my own warning talk about the evils of Globals.
The kids wanted to do something beyond the EV3-G environment, so we've all tried to muddle our way through Python this FLL season and I'm luckily a few steps ahead of the kids.
Thanks @dlech and @WasabiFan for the late night help.
BTW: It also began running WAYYYYY faster than before - like 5-6 seconds.
Glad to hear it! Classes in this library are designed to be instantiated once then used forever, so they're optimized for that case. Good to hear it's faster.
WHAT'S GOING ON:
My team was running a test of a function for their EV3 robot called FORWARD. Using nested loops to increment the power and distance, they were evaluating the error in the function.
Without fail, after running the command with new variables, 46 times, on the 47th, they got this error message.
OSError: 24 is "Too many files open" according to what I could find.
I have no idea what that means.
I have a 64GB card that EV3DEV2 is loaded on.
There is no error handling in the function or the module.
I don't think this will affect us in competition as there probably won't be more than 20 move/turn function calls per run.
Any thoughts on what this is, or what can be done would be appreciated.