Find Me - Mode

Firmware/software/electronics/mechanics
Post Reply
Surrender
Expert
Posts: 100
Joined: Tue May 14, 2013 8:31 pm
Location: Austria

Find Me - Mode

Post by Surrender » Mon Jun 17, 2013 1:57 pm

Hello there ;)

This week (or maybe next) i want to start developing a test version of the "find me" - mode.

As i mentioned before in another thread:
This will be a great feature because the CF is so small that it's hard to find outside. I'm not the only one wo lost this crazy little thing.
There might be three lightweight (max ~2g) solutions:

1) Make sound with the motors using another PWM frequency (in between 5 - 8kHz) -> 0g additionally
This "come find me mode" should be activated if the connection is lost. The motors should shutdown when the voltage reaches ~3050mV to prevent a cut-off.
After the shutdown the voltage is raising, now the PWM should be activated to make the search mode running.
Would be also a nice idea to make music during the fly (changing PWM frequency for sound and PWM duty cycle for motor speed).

Concrete:
- Motor shutdown @ ~3050mV (@3000mV -> cut-off)
- Start the soundmaking PWM (one frequency beep for finding, EDIT: Loudest sound @res. freq. e.g. 6kHz) with a duty cycle of ~ 15%

I've looked in the crazyflie firmware sourcecode and i think it is not hard to add a mode where the PWM frequency is not 140kHz but e.g. 6kHz. I have to change (add new definitions in motors.h) the MOTORS_PWM_BITS to 10 and the MOTORS_PWM_PRESCALE to 16. In motors.c i will add a function with sets the frequency and starts this. I don't know in wich part but i have to check the battery and then start the function (maybe somebody knows where to put that).

I want to start to develop the firmware but i have one question: What happens if there is a bug or mistake in the firmware? Is the bootloader always the same that I can upload all what i want without damage effect? (I want to use the wireless bootloader -> no JTAG environment available).

2) Hack a key finder (http://loc8tor.com/) -> ~$44 & 2g when hacked (~6g with case etc)
foosel had that idea, look here: Link to post

3) Add a piezzo for making a loud sound (~60 up to 80dB) -> adds about 1-2g, connected to extension header
I tried to find a lightweight piezzo but its not that easy. They also costs about 4€ which is not that less. Maybe someone found a good, cheap and lightweight one. :D

Hopefully we find a solution, because a lost crazyflie is a lost one. ;)

Greetings



tobias
Bitcraze
Posts: 1919
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Find Me - Mode

Post by tobias » Mon Jun 17, 2013 9:21 pm

Great that you want to work on this Surrender! I did a quick testing function that can make a sound that seem to be working:

Code: Select all

void motorsBeep(bool enable, uint16_t frequency)
{
  uint16_t period;
  uint16_t ratio;
  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;

  if (enable)
  {
    period = (uint16_t)(72000000L / frequency);
    ratio = period / 100;
  }
  else
  {
    period = MOTORS_PWM_PERIOD;
    ratio = 0;
  }
  //Timer configuration
  TIM_TimeBaseStructure.TIM_Period = period;
  TIM_TimeBaseStructure.TIM_Prescaler = MOTORS_PWM_PRESCALE;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(MOTORS_GPIO_TIM_M1_2, &TIM_TimeBaseStructure);
  TIM_TimeBaseInit(MOTORS_GPIO_TIM_M3_4, &TIM_TimeBaseStructure);

  TIM_SetCompare4(MOTORS_GPIO_TIM_M1_2, ratio);
  TIM_SetCompare3(MOTORS_GPIO_TIM_M1_2, ratio);
  TIM_SetCompare4(MOTORS_GPIO_TIM_M3_4, ratio);
  TIM_SetCompare3(MOTORS_GPIO_TIM_M3_4, ratio);
}
You can't erase the bootloader if you don't write code that deliberately do it.

A motor sound driver would be really sweet and probably not impossible. One could probably even stream sound data over the radio. A super portable speaker :D

Surrender
Expert
Posts: 100
Joined: Tue May 14, 2013 8:31 pm
Location: Austria

Re: Find Me - Mode

Post by Surrender » Tue Jun 18, 2013 8:13 pm

I have no overview, can you tell me, where you put this piece of code to (i think the function definition in motors.h and the body into motors.c - right?) and where do you call this method?
I tried this (added it after motorsTest() in the stabilizer.c) but when i increase thrust i hear a sound for 1s and then the CF is disconnected.

:D

tobias
Bitcraze
Posts: 1919
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Find Me - Mode

Post by tobias » Thu Jun 20, 2013 11:07 am

Yes, I put it in motors.c and I just did a simple test which I ran from the motorsTest function:

Code: Select all

bool motorsTest(void)
{
  int i;

  for (i = 0; i < sizeof(MOTORS) / sizeof(*MOTORS); i++)
  {
    motorsSetRatio(MOTORS[i], MOTORS_TEST_RATIO);
    vTaskDelay(M2T(MOTORS_TEST_ON_TIME_MS));
    motorsSetRatio(MOTORS[i], 0);
    vTaskDelay(M2T(MOTORS_TEST_DELAY_TIME_MS));
  }

  for (i = 1000; i < 10000; i += 100)
  {
    motorsBeep(TRUE, i);
    vTaskDelay(M2T(100));
    motorsBeep(FALSE, i);
  }

  return isInit;
}

Surrender
Expert
Posts: 100
Joined: Tue May 14, 2013 8:31 pm
Location: Austria

Re: Find Me - Mode

Post by Surrender » Wed Jun 26, 2013 7:51 pm

'Evening,

@ Tobias: Where can i find the code which is executed when the connection to the transmitter is lost? And how/where do i check the battery value in the crazyflie firmware?

Esky specific: Why is it not possible to reconnect with the esky transmitter after a disconnect? I have to restart the crazyflie. This is not really good because when e.g. the CF is lost and i want to turn on the motors to hear something -> it is not possible.

Thanks :)

PS: Sorry for this questions but there are so much files in the CF firmware .. ;)

DesTinY
Member
Posts: 97
Joined: Sat Feb 09, 2013 5:18 pm
Location: Bünde, Germany

Re: Find Me - Mode

Post by DesTinY » Wed Jun 26, 2013 10:53 pm

Battery info: float pmGetBatteryVoltage(void)
To generate a sound if the Battery is full charged: pmUpdateState()

Maybe this Send a warning message if the battery voltage drops under 3.3V is interesting for you, too.

tobias
Bitcraze
Posts: 1919
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Find Me - Mode

Post by tobias » Thu Jun 27, 2013 7:18 am

Esky specific: Why is it not possible to reconnect with the esky transmitter after a disconnect? I have to restart the crazyflie. This is not really good because when e.g. the CF is lost and i want to turn on the motors to hear something -> it is not possible.
I think it is because the Crazyflie is now setup to "pair" with the transmitter for the first connect but doesn't afterwards. I don't think it would be that difficult to update the code to handle reconnect as well.

Post Reply