using motorsBeep() or motorTest()

Firmware/software/electronics/mechanics
Post Reply
ariel
Beginner
Posts: 3
Joined: Tue Jul 23, 2019 4:40 pm

using motorsBeep() or motorTest()

Post by ariel » Tue Jul 23, 2019 6:34 pm

Hi,
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.
Ariel.



kimberly
Expert
Posts: 110
Joined: Fri Jul 06, 2018 11:13 am

Re: using motorsBeep() or motorTest()

Post by kimberly » Wed Jul 24, 2019 8:55 am

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?

ariel
Beginner
Posts: 3
Joined: Tue Jul 23, 2019 4:40 pm

Re: using motorsBeep() or motorTest()

Post by ariel » Wed Jul 24, 2019 1:37 pm

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.

kimberly
Expert
Posts: 110
Joined: Fri Jul 06, 2018 11:13 am

Re: using motorsBeep() or motorTest()

Post by kimberly » Thu Jul 25, 2019 8:24 am

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)
	  motorsPlayTone(262,500);
    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?

ariel
Beginner
Posts: 3
Joined: Tue Jul 23, 2019 4:40 pm

Re: using motorsBeep() or motorTest()

Post by ariel » Sat Jul 27, 2019 8:26 am

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.

Post Reply