Help with weird motor bug

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

SUPERETDUPER
New User
Posts: 15
Joined: Sat Apr 15, 2017 8:52 pm

Help with weird motor bug

Postby SUPERETDUPER » Sun Apr 29, 2018 10:02 pm

Hey, me and my teammates are doing a wro robotics competition and we are experiencing a weird bug we think is at the motor level in the source code. When we call forward or rotate methods on motors this happens occasionally and randomly:
the motor speed increases significantly,
the motor goes crazy and doesn't respond for a bit then sometimes it will stay like that forever and other times it will return to our original code.

SUPERETDUPER
New User
Posts: 15
Joined: Sat Apr 15, 2017 8:52 pm

Re: Help with weird motor bug

Postby SUPERETDUPER » Sun Apr 29, 2018 10:56 pm

Temporarily solved it with a delay between motor calls. Must be a threading issue somewhere in source code. Maybe the 2 commands are being sent at the same time to the motors or something. :(

User avatar
gloomyandy
leJOS Team Member
Posts: 6047
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Help with weird motor bug

Postby gloomyandy » Mon Apr 30, 2018 6:28 am

It probably isn't a bug, more likely it is the way you are using the motors, the motor code (like most of the hardware related code in leJOS) is not thread safe. This means you should not be sending motor commands to a motor from two different threads, that is never a good idea, especially if you are not using thread synchronization to control how you access the device. Adding delays will not fix this sort of issue, it will only mean that it happens less often. If you want to to fix it properly either move your motor commands so they are all in the one thread, or take the time to add the correct critical sections and synchronization to your code. It really isn't that hard and there are many tutorials out there that will show you how to use Java threads correctly. If you don't do this you will almost certainly find that things will go horribly wrong just when you don't need it, probably in a competition.
leJOS news https://lejosnews.wordpress.com/

User avatar
jippiee
New User
Posts: 12
Joined: Tue Dec 26, 2017 1:07 am

Re: Help with weird motor bug

Postby jippiee » Wed May 16, 2018 10:14 pm

I'm having the same issue, but it seems to be somehow related to the chassis. I have a linefollower using the "chassis.setVelocity(...)" method and the "chassis.travel(...)" / "chassis.rotate(...)" and "chassis.arc(...)" methods, which are followed by a "chassis.waitComplete()", running after each other in the main thread.
( Before I used the pilot methods, but then the problem seemed far more frequent)

The Bug can randomly occur when e.g. a rotation is complete and the linefollower should start, but the robot turns uncontrollably further, with what seems to be the maximum speed.

This probably occurs, because two methods try to access the motors at the same time.

I'm not entirely sure what causes the bug, but I've got an assumption:

The "chassis.setMotors(...)" method calls "master.endSynchronisation()", which calls "reg.endSynchronization(true)" from the BaseRegulatedMotor class.

The parameter "immRet" of the "endSynchronization(boolean immRet)" determines, whether or not to wait for the synchronization process to end (correct me if I'm wrong)

Shouldn't this be set to false? This way the motors would need to finish turning before the next method can be started. Or at leased the parameter should get passed on to the BaseRegulatedMotor "endSynchronization()" method.

That way the "setMotors(...)" could wait for the Synchronization (and the complete move) to finish, while the "setVelocity(...)" method could return immediately.

User avatar
gloomyandy
leJOS Team Member
Posts: 6047
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Help with weird motor bug

Postby gloomyandy » Fri May 18, 2018 7:40 am

You are wrong :-). The Chassis model does not provide "blocking moves" it is intended for continuous motion, this means that things like rotate/arc/travel simply start the move (and cancel any in progress motion), if you want to wait for the motion to complete you can call waitComplete. If you want stop/start motion then use the MovePilot (which builds on top of the Chassis) which will wait for each operation to complete.
leJOS news https://lejosnews.wordpress.com/


Return to “EV3 Software”

Who is online

Users browsing this forum: No registered users and 1 guest