voxl_esc tone bug and question
-
I can play tones on the ESC via the following command (after running
px4-alias.sh
) :qshell voxl_esc -i 1 -p 50 -d 30 -v 20 tone
This should actually be
qshell voxl_esc tone -i 1 -p 50 -d 30 -v 20
but that will fail because voxl_esc will take the last command as verb but it should take argument index 2 as verb.const char *verb = argv[argc - 1];
should be
const char *verb = argv[2];
If you put the tone in front you get the following usage message:
Aug 06 10:10:11 SPOT voxl-px4[11774]: INFO [muorb] SLPI: Aug 06 10:10:11 SPOT voxl-px4[11774]: ### Description Aug 06 10:10:11 SPOT voxl-px4[11774]: This module is responsible for... Aug 06 10:10:11 SPOT voxl-px4[11774]: ### Implementation Aug 06 10:10:11 SPOT voxl-px4[11774]: By default the module runs on a wor Aug 06 10:10:11 SPOT voxl-px4[11774]: INFO [muorb] SLPI: Usage: voxl_esc <command> [arguments...] Aug 06 10:10:11 SPOT voxl-px4[11774]: INFO [muorb] SLPI: Commands:
which says the <command> (
tone
) should be in front of the arguments.
I have a question about the usage. The documentation says this:
Aug 06 10:10:28 SPOT voxl-px4[11774]: tone Send tone generation request to ESC Aug 06 10:10:28 SPOT voxl-px4[11774]: INFO [muorb] SLPI: -i <val> ESC ID, 0-3 Aug 06 10:10:28 SPOT voxl-px4[11774]: INFO [muorb] SLPI: -p <val> Period of sound, inverse frequency, 0-255 Aug 06 10:10:28 SPOT voxl-px4[11774]: INFO [muorb] SLPI: -d <val> Duration of the sound, 0-255, 1LSB = 13ms Aug 06 10:10:28 SPOT voxl-px4[11774]: INFO [muorb] SLPI: -v <val> Power (volume) of sound, 0-100
I want to know how the period relates to the tone frequency in Hz. The documentation is not correct or incomplete because I can hear a sound with period=0 which should be an infinitely high frequency. When I want to play a tone of 2110 Hz, the inverse is 0,0004739 seconds. I thought there is maybe a scaling factor of 1e5 to make it within the range of 0-255 but the sounds I hear do not match up with the frequencies I expect. How does it work?
-
@Tjark , thank you for the bug report in the voxl_esc driver, i will check it out.
As for the tone command itself, you are absolutely correct that the tone frequency mapping is not what you would expect and I have started working on fixing it. Rather than explaining what the current firmware does, I just want to fix it so that you can actually have a direct mapping to hz.
Let me get back to you later this week with updated firmware. By the way, i recently added a python script for testing tones (on a feature branch) : https://gitlab.com/voxl-public/voxl-sdk/utilities/voxl-esc/-/blob/enable-pwm-outputs/voxl-esc-tools/voxl-esc-tone.py . If you are familiar with
voxl-esc
tools, you can test it out.Alex
-
@Alex-Kushleyev Thanks for your response. Sounds good.
For some background, we currently only put power on the ESC when we are about to fly. When the ESC is powered, the startup sound can be heard which is an audio notification to anybody closeby that this drone can soon start spinning up his motors. With the new PX4 firmware in sdk-1.3, there is a version check in the ESC initialization which now fails because we haven't powered the ESC at that moment. We're now thinking of keeping the ESC always powered but we still want to have this audio notification when the drone is about to fly. So that's why I was looking into this and also wanted to mimic our startup tone with the same frequencies. It would be nice if we could also send a sequence of tones or reference to preconfigured sounds but else I will just send multiple commands after each other. The python script looks nice but it doesn't work for us because it requires voxl-px4 to be not running. If you have a better suggestion of playing the tones I would be interested to hear it.
-
@Tjark , I understand exactly what you are asking. Let me think about this. I could potentially add an option to just play the start-up tone upon receiving a single tone command. I could use a special value of the existing tone message to just trigger the start-up tone playback.
So I am considering two small updates related to this:
- fix the tone generation to more accurately reflect desired frequency in Hz
- add a special value in the tone message to trigger the playback of a start-up tone, so you can just send a single command from PX4
How does that sound?
Alex
-
@Tjark , I added new firmware to my test branch, which enables playing of init tone when you send the special tone command (0 power, 0 duration, 0 frequency). This firmware also has some other new test features (pwm output capability), but you should be able to safely use it for testing as well.
firmware v39.20 : link. You can upload it using
voxl-esc
tools right on VOXL2, while PX4 is not running.After that, you can try the init tone test command (all tone parameters set to zero):
qshell voxl_esc -i 1 -p 0 -d 0 -v 0 tone
your ESC initialization tone (specified in ESC params) should play. Please keep one thing in mind -- right now while the sound is playing the ESC temporarily stops communicating with PX4 during the tone, but since the tone can only be played when the motor is not spinning (px4 is disarmed), there should not be any harm, but let me know if you notice any warnings from PX4 (like ESC timeout or something like that) -- i think it should be ok.
I also found another bug in the tone command in px4 -- the
-i
option accepts ESC IDs 0-3, but the tone command that is being sent out actually accepts a mask, so if you want all ESCs to make the tone, you would need to set the mask to 15 (or 255..) but the voxl_esc px4 command only allows values 0-3. So if you set-i 1
, this will only play the sound with one motor (0th bit is set, so that is the first motor, ESC id=0 or px4 motor ID 1).I will fix the tone command.. if you want to fix it for your testing, you can just set the esc_id that is being passed to
create_sound_packet
function to 255 (link) -
@Alex-Kushleyev Thanks for the update! Sorry for my slow response. I was away since last Thursday. Sounds great to use the 0 values for the startup tone. That is really helpful. I will test this as soon as I can. Did you also change the frequency mapping (although I don't think I need this if I use the startup tone)?
Will you still make the change from
qshell voxl_esc [arguments...] <command>
toqshell voxl_esc <command> [arguments...]
? If not, can you update the print_usage: https://github.com/modalai/px4-firmware/blob/main/src/drivers/actuators/voxl_esc/voxl_esc.cpp#L1350 to match with the actual usage? -
@Tjark , I did change the tone mapping that is generated from the tone command. It used to be not consistent with the convention that is used for the start-up tones. So firmware version 39.20 will have that change. However, i still did not verify or change it to match any specific frequency.
Let me check with the team about the usage change. Perhaps we just update the print_usage so that we are not making a breaking change in the actual command syntax (and cause someone else's code to break)
As for generating tones of specific frequencies, i am most likely going to add a new packet in order to support tones of correct frequency and higher resolution. Currently the tone packet only allows 8 bit to specify the frequency, which is not sufficient.
For now, do you want me to provide the mapping between the 0-255 frequency values to actual frequencies in Hz ?
-
@Alex-Kushleyev I tested it and it works nice (I didn't test the 255 but I expect that should work). I already figured that the frequencies are now multiples of 10Hz with some minimum value (I don't know which one but at least below -p 10 I don't hear the frequency drop anymore). So it ranges up to 2550Hz. And I think you also adjusted the duration to be multiples of 10ms to match with the format of the ESC parameters?
Regarding the usage change, I understand if you don't want to create a breaking change. But I think it would be good when the print_usage matches with the actual use. It took me some trial and error to get it working. Maybe also an idea to use -f for the frequency because -p refers to period which is not correct anymore and it is now already changing the functionality of the tone generation (you could even let -p in it to keep it backwards compatible but that maybe makes it unnecessarily complicated). And also good to allow the ESC mapping to go up to 15.
For us it is sufficient to use the startup tone. But I played around a little bit with the tone generation and if you use it using the qshell commands you need to wait the duration of the tone to send a new tone (as the qshell command immediately returns and it doesn't accept a command while the sound is still playing) which makes it difficult to get the timing right in playing a tune. I don't know what the end goal should be of this but if it is playing custom tunes using the commands this is something to keep in mind I think. I had some fun trying to play the Imperial March on the ESCs which kind of works but not as smooth as the startup sound can play.