Page 1 of 1

using motorsBeep() or motorTest()

Posted: Tue Jul 23, 2019 6:34 pm
by ariel
i am trying to make the motors sound and turn as they do after turning on the crazyflie, but at will every time i send the right message (the message part is already implemented and well tested).
For what i have seen the function i need to call is motorsTest. However, when i call it nothing happens. I also tried calling motorsBeep or even motorsSetRatio. And again, nothing happens. My guess is that something needs to be set in order to those commands arrive to the motors, but i dont seem to be able to find it.
The basic idea is to be able to have a visual feedback of the cf connection to the pc. I already was able to send commands to set some ledSequences as well as getting battery voltage and pressure readings, all in a new rtos task. However, as i said, i seem to be unable to set any action that requires connection to the motors.
I would appreciate your help if can point me out what needs to be done in order to use motorsTest or similar functions at will, thank you.

Re: using motorsBeep() or motorTest()

Posted: Wed Jul 24, 2019 8:55 am
by kimberly
Hi Ariel!

So if I understand correctly, you want the crazyflie to also do the motor sequence sound thingy if it connect to the computer, next to the red/yellow m4 LED that already lights up with connection?

Good place to start is to investigate crazyflie-firmware/src/drivers/src/motor.c, because the function motorTest() is where that startup sequence is being called. That is being called by the power_distribution_stock.c where you can also set the pwm per motor through a parameter.

Does this help?

Re: using motorsBeep() or motorTest()

Posted: Wed Jul 24, 2019 1:37 pm
by ariel
hi kimberly,

yes i want to be able to run the starting sequence sound thingy from the firmware. As you say this should be done by using motorTest(), but after calling it nothigns happens. I took a look at power_distribution_stock.c and as you say powerdistribution init calls motorTest, and nothing else fancier.
In that file there is a bool called motorsetenable, i have tried forcing it to true, but agains nothings happens.
Maybe the way to go is with parameters as you said, There is any way to modify an call parameters within the firmware??
I dont really know what is happening, it appears to me that at start up the starting sequence sound thingy is simply executed by calling motorTest in motors.c. But i dont see a way to replicate this.

Re: using motorsBeep() or motorTest()

Posted: Thu Jul 25, 2019 8:24 am
by kimberly
I'm not sure how you have implemented it, but if I would put the motorTest() later in the systemTask() loop in system.c, (with the motors.h in the header ofcourse), it will do the motor initialization tune twice in a row.

You could look at the motorsPlayTone() and use that to check the ctrp connection. I for instance put it in ctrpIsConnected()

Code: Select all

bool crtpIsConnected(void)
  if (link->isConnected)
    return link->isConnected();
  return true;
and then you see the motors react as soon it is connected with the crazyradio. It does it all the time though so it can be a bit annoying, but you could right a module for yourself that runs next to this and only does it once.

About the motorssetenable, that is something different. You can test it out by going to the cfclient->parameters, set motorPowerSet.M1 to 5000 (this is a very slow spin so don't worry!), and afterwards set the motorPowerSet.enable to 1. This will spin motor M1.

About setting parameters from the firmware itself, currently there is no direct readout of parameters, so you will need to make an extern from the variables you want to read and set from another file/module. However, if you want to do it properly, you can look at the way we did this for the logging (log.h). There are functions in there, like logGetFloat/ logGetGroupAndName, that make it possible for any module in the firmware to read out a log variable. You can do something similar for the parameters?

Re: using motorsBeep() or motorTest()

Posted: Sat Jul 27, 2019 8:26 am
by ariel
Im this days out, but i will try it as soon as possible and share the results, but that looks very promising. Thanks for the help.