RMIRegulatedMotor doesn't return getCurrentSpeed()

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

Moderators: roger, gloomyandy, skoehler

edouardo17
New User
Posts: 2
Joined: Wed Oct 25, 2017 11:06 am

RMIRegulatedMotor doesn't return getCurrentSpeed()

Postby edouardo17 » Tue Nov 28, 2017 12:11 pm

Hi all!

I am having trouble to get the current velocity of my RMIRegulatedMotor on my EV3 brick... My objective is to display my current motor speed in a dedicated Gauge on my interface.
I have a dedicated thread which asks the brick every 200ms for the current steering angle, and the current motor speed. I am using the RMIRegulatedMotor class as I am controlling my EV3 via a Bluetooth connection and for other reason which implies that I don't intend to change to a more common Motor class of the leJOS library.

With that said, I apply this code to get the current velocity of my motor:

Code: Select all

if (MotorControl_v2.leftMotor.isMoving()) {
         speed = MotorControl_v2.leftMotor.getSpeed();
   } else speed = 0;


The result on my interface bellow is that the speed gauge jumps to 720 rpm when I start the motor (by pressing NUMPAD.8 ) and returns straight to zero when the motor stops... which is not what I want because I set the acceleration at 300 degres/s/s, so every 200ms, I should see a jump of about 60 rpm... but I don't

Image

My question is: how can I get the true CURRENT rotation velocity of my motors?
Many thanks in advance for your help!

Edouard

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

Re: RMIRegulatedMotor doesn't return getCurrentSpeed()

Postby gloomyandy » Tue Nov 28, 2017 5:16 pm

Sorry I'm afraid there is no easy way to do this. At some point the getCurrentSpeed method was added to the regulated motor class but no corresponding change was made to any of the remote implementations (one of the many reasons why I don't like the leJOS remote implementation), as a result that method is not available via the remote API. You could add the method yourself to the RMIRemoteRegulatedMotor and RMIRegulatedMotor classes and then rebuild the classes library and also probably menu, you will also need to replace the ev3classes.jar and ev3 menu jar files on your EV3. It is not a huge job but will mean that you need to set things up to allow you to build leJOS.

The alternative (which I will always recommend), is to stop using the leJOS remote API and instead create your own remote API with some of your own code running on the EV3. This will allow you to control exactly what code runs on the EV3 and what code runs on the PC which in term allows you to ensure that time critical code runs on the EV3 and toi minimize the bandwidth required for the connection. To see more of what I'm talking about take a look at this series of articles that describes the standard remote API and that also describes a very simple custom remote API...
https://lejosnews.wordpress.com/2015/02 ... e-methods/
https://lejosnews.wordpress.com/2015/03 ... dont-work/
https://lejosnews.wordpress.com/2015/03 ... -take-two/
leJOS news https://lejosnews.wordpress.com/

Aswin
leJOS Team Member
Posts: 312
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands
Contact:

Re: RMIRegulatedMotor doesn't return getCurrentSpeed()

Postby Aswin » Tue Nov 28, 2017 5:24 pm

Hi,

The setSpeed and grtSpeed methods deal with the target speed of the motors. To get the actual speed of a motor you can use getRotationSpeed. This method not available using a remote interface or class. So you will have to find another way to get the actual speed.
Here are some alternatives.
- design your own protocol to remotely accessing the brick using dockets
- create a sampleprovider that returns actual speed and remotely access this sampleprovider
- use MQTT messaging, there is an explanation here.
My NXT blog: http://nxttime.wordpress.com/

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

Re: RMIRegulatedMotor doesn't return getCurrentSpeed()

Postby gloomyandy » Tue Nov 28, 2017 5:50 pm

Oops Aswin is of course correct the method to use is getRotationSpeed (though arguably getCurrentSpeed or even getCurrentVolocity would have been a better choice for the method name!).
leJOS news https://lejosnews.wordpress.com/


Return to “EV3 Software”

Who is online

Users browsing this forum: No registered users and 1 guest