Repository navigation
Error on non-existing arguments/parameters - #278
Conversation
It turns out these are all auto generated, trashing previous manual changes.
I hope I got all of them now.
|
What is |
In the code the field is used as a cache to store the value (and save an access to |
|
If this makes property access faster it would be nice to see some timeit before and after. Could be a worthy addition to the release notes, since speed improvements help to cut latency on control loops. |
ddemidov
left a comment
There was a problem hiding this comment.
This looks good to me. Can you add the change for the _bin_data_size so that the tests pass?
@dwalton76, I think your mindcub3r example is the most extensive one we have. If you still have the robot around, could you please check this does not break anything?
We also have classes in ev3dev.helper that inherit from Motors. Do we need to add __slots__ there as well?
|
yep I will give it a try |
|
I'm not sure what a good test is to test performance of this change, TBH probably most time is spend talking to the kernel, compared to one dictionary lookup. I fixed the data size, which was rather straightforward. The helper classes require a bit more thought. As it stands now, using the helper classes would add an internal dict, allowing undefined attributes as before. |
|
I think this one needs some more testing. I cannot pinpoint what is wrong but when using this patch my robot failed to solve the rubiks cube three times in a row, without this patch it can solve it everytime. All motors look like they are rotating the correct amount (the cube would get jammed up otherwise) but I suspect one is turning in the wrong direction in some scenario. |
|
Weird. No errors? (or things that swallow errors) If the robot is deterministic, I suppose you could use the same scramble and see where it goes wrong. Or just plain old printf debugging.Ik might be able to do some more testing, but simple things seemed to work and without knowing more it's hard to know where to look.Is this robot of yours one I can reproduce with my own ev3 (software and instructions available), or a custom monster with tons of extra parts?
|
This is not my robot, but I believe its built according to these instructions: http://mindcuber.com/mindcub3r/mindcub3r.html. And the program is here: https://github.com/rhempel/ev3dev-lang-python/tree/develop/demo/MINDCUB3R |
|
MINDCUBER is a good way to test, a lot of things have to be perfect for it to solve the cube. I'm actually using my own cube solver now, if you have a 42009 (the big crane) then you can build it. I need to put together instructions though. Let me do this, I can put the cube back in the same scrambled state and record a video of it being solved with and without your patch. Then I can compare the two videos side by side and see where it is behaving differently. That should help narrow it down a bit. |
|
Ignore what I said, I suspect I have an error on my end. |
|
A simple performance test shows there is a bit of improvement, or at least it is definitely not worse: Before >>> import timeit
>>> timeit.repeat('s.proximity', 'from ev3dev.ev3 import InfraredSensor; s = InfraredSensor()', number=100)
[4.144548124999972, 3.950399667000056, 4.128440291999993]
>>> timeit.repeat('s.proximity', 'from ev3dev.ev3 import InfraredSensor; s = InfraredSensor()', number=100)
[3.9438115419999917, 4.096679416999962, 3.8801820420000013]
>>> After >>> import timeit
>>> timeit.repeat('s.proximity', 'from ev3dev.ev3 import InfraredSensor; s = InfraredSensor()', number=100)
[3.8830312090000234, 4.003896959000031, 3.78919083400001]
>>> timeit.repeat('s.proximity', 'from ev3dev.ev3 import InfraredSensor; s = InfraredSensor()', number=100)
[3.8567800419999685, 3.932827876000033, 3.8972169590000476]
>>> But I think the main idea here was to help users by catching semantic errors early. |
|
Thanks! |
|
Awesome. Still curious what happened on @dwalton76 's end though. |
|
I have a bug where I sometimes assign the wrong color to a cube square based on the RGB values. In a nutshell you have 54 RGB tuples and from that you have to assign each square to be one of the six colors of the Rubik's cube. I had this fairly rock solid but have been working on this code to make it support 4x4x4, 5x5x5, etc cubes and must have introduced a bug because when I took a video of it solving with your patch in place I noticed that it got some of the color assignments wrong. |
|
In another run I was able to solve a cube with your patch applied so the motor movements seem to be fine. |
This patch adds
__slots__to all API classes that usesetattrmagic andkwargsfor function parameters. Besides reducing memory and speeding up access, the main point of this change is that a typo when calling a function will result in an error, rather than silently setting non-existing properties.Currently the last line would just set the
speed_sdproperty on the object, without doing anything, leaving it up to you to figure out why your motor went berserk or did nothing at all.With the proposed change, you get instant feedback that you're doing something stupid.