[crazyflie 2.0] [solved] constant crashing and motors failing to activate.
Posted: Sun Jan 03, 2021 10:21 pm
We are trying to make multiple crazyflies broadcast a message constantly and to pass along any message they receive. We made them signal when they received a message and passed it along by activating a single motor.
But we encountered two problems we cannot identify.
The first is that on random accordance one of the crazyflies will stop working. When in this stage only one blue led remain lit and nothing else. It needs to be restarted to work.
The second is that sometimes the crazyfiles keep passing the message along without activating the motors. They usually need to be restarted to work, but sometimes they just work again without doing anything.
If anyone has any suggestions for the source of the two problems please answer.
Here is the code we use, its a modified version of the peer_to_peer example:
But we encountered two problems we cannot identify.
The first is that on random accordance one of the crazyflies will stop working. When in this stage only one blue led remain lit and nothing else. It needs to be restarted to work.
The second is that sometimes the crazyfiles keep passing the message along without activating the motors. They usually need to be restarted to work, but sometimes they just work again without doing anything.
If anyone has any suggestions for the source of the two problems please answer.
Here is the code we use, its a modified version of the peer_to_peer example:
Code: Select all
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include "app.h"
#include "FreeRTOS.h"
#include "task.h"
#include "deck.h"
#include "radiolink.h"
#include "configblock.h"
#define DEBUG_MODULE "P2P"
#include "debug.h"
#include "log.h"
#include "param.h"
#include "commander.h"
#include "deck_digital.h"
#include "deck_analog.h"
#define MESSAGE "warning!!!"
#define MESSAGE_LENGHT 11
void p2pcallbackHandler(P2PPacket *p)
{
// Parse the data from the other crazyflie and print it
uint8_t other_id = p->data[0];
static char msg[MESSAGE_LENGHT + 1];
memcpy(&msg, &p->data[1], sizeof(char)*MESSAGE_LENGHT);
msg[MESSAGE_LENGHT] = 0;
uint8_t rssi = p->rssi;
DEBUG_PRINT("[RSSI: -%d dBm] Message from CF nr. %d, %s\n", rssi, other_id, msg);
static P2PPacket p_reply;
p_reply.port=0x00;
// Get the current address of the crazyflie and obtain
// the last two digits and send it as the first byte
// of the payload
uint64_t address = configblockGetRadioAddress();
uint8_t my_id =(uint8_t)((address) & 0x00000000ff);
p_reply.data[0]=my_id;
//Put a string in the payload
char *str="warning!!!";
memcpy(&p_reply.data[1], str, sizeof(char)*MESSAGE_LENGHT);
// Set the size, which is the amount of bytes the payload with ID and the string
p_reply.size=sizeof(char)*MESSAGE_LENGHT+1;
vTaskDelay(M2T(200));
radiolinkSendP2PPacketBroadcast(&p_reply);
//------------------------------------------------------------------------------------------
// pinMode(DECK_GPIO_IO1, OUTPUT); // Set my Led pin to output
// digitalWrite(DECK_GPIO_IO1, HIGH); // Light it up
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
paramVarId_t idEstimator = paramGetVarId("motorPowerSet", "m1");
uint16_t new_value = 10000;
paramSetInt(idEstimator, new_value);
vTaskDelay(M2T(500));
new_value = 0;
paramSetInt(idEstimator, new_value);
//------------------------------------------------------------------------------------------
}
void appMain()
{
DEBUG_PRINT("Waiting for activation ...\n");
uint16_t idUp = logGetVarId("range", "up");
uint16_t up = logGetUint(idUp);
paramVarId_t idEstimator = paramGetVarId("motorPowerSet", "enable");
uint8_t new_value = 1;
paramSetInt(idEstimator, new_value);
// In itialize the p2p packet
static P2PPacket p_reply;
p_reply.port=0x00;
// Get the current address of the crazyflie and obtain
// the last two digits and send it as the first byte
// of the payload
uint64_t address = configblockGetRadioAddress();
uint8_t my_id =(uint8_t)((address) & 0x00000000ff);
p_reply.data[0]=my_id;
//Put a string in the payload
char *str="warning!!!";
memcpy(&p_reply.data[1], str, sizeof(char)*MESSAGE_LENGHT);
// Set the size, which is the amount of bytes the payload with ID and the string
p_reply.size=sizeof(char)*MESSAGE_LENGHT+1;
// Register the callback function so that the CF can receive packets as well.
p2pRegisterCB(p2pcallbackHandler);
while(1)
{
// Send a message every 0.5 seconds
// Note: if they are sending at the exact same time, there will be message collisions,
// however since they are sending every 0.5 seconds, and they are not started up at the same
// time and their internal clocks are different, there is not really something to worry about
up = logGetUint(idUp);
if(up < 300.f && up > 0.001f)
{
vTaskDelay(M2T(500));
radiolinkSendP2PPacketBroadcast(&p_reply);
}
}
}