snippet_ros_to_ardrone_config.h
Go to the documentation of this file.
00001 #ifndef SNIPPET_ROS_TO_ARDRONE_CONFIG_H
00002 #define SNIPPET_ROS_TO_ARDRONE_CONFIG_H
00003 
00004 // LOAD THE CUSTOM CONFIGURATION FROM ROS PARAMETERS
00005 // all possible configuration parameters are stored in config_keys.h (and documented in the manual)
00006 // taking inspiration from ardrone_tool_configuration.c,
00007 // we define some macros that replace these parameter definitions
00008 // with a function which attempts to read corresponding ros parameters,
00009 // and then if successful, sets the parameter value for the drone
00010 // Note that we don't actually send these parameters to the drone,
00011 // otherwise they will be overwritten when the profiles are created
00012 // in a later stage of the ARDrone initialization.
00013 
00014 #undef ARDRONE_CONFIG_KEY_IMM_a10
00015 #undef ARDRONE_CONFIG_KEY_REF_a10
00016 #undef ARDRONE_CONFIG_KEY_STR_a10
00017 #undef LOAD_PARAM_STR
00018 #undef LOAD_PARAM_NUM
00019 
00020 #define LOAD_PARAM_NUM(NAME,C_TYPE,DEFAULT)                                                                             \
00021         {                                                                                                                   \
00022           double param;                                                                                                     \
00023           ROS_DEBUG("CHECK: "#NAME" (Default = "#DEFAULT" = %f)",(float)DEFAULT);                                           \
00024           if(ros::param::get("~"#NAME,param))                                                                               \
00025           {                                                                                                                 \
00026             ardrone_application_default_config.NAME = (C_TYPE)param;                                                        \
00027             ROS_DEBUG("SET: "#NAME" = %f (DEFAULT = %f)", (float)ardrone_application_default_config.NAME, (float)DEFAULT);  \
00028           }                                                                                                                 \
00029         }
00030 
00031 #define LOAD_PARAM_STR(NAME,DEFAULT)                                                                                    \
00032         {                                                                                                                   \
00033           std::string param;                                                                                                \
00034           ROS_DEBUG("CHECK: "#NAME" (Default = "#DEFAULT" = %s)",DEFAULT);                                                  \
00035           if(ros::param::get("~"#NAME,param))                                                                               \
00036           {                                                                                                                 \
00037             param = param.substr(0,STRING_T_SIZE-1);                                                                        \
00038             strcpy(ardrone_application_default_config.NAME , param.c_str());                                                \
00039             ROS_DEBUG("SET: "#NAME" = %s (DEFAULT = %s)", ardrone_application_default_config.NAME, DEFAULT);                \
00040           }                                                                                                                 \
00041         }
00042 
00043 #define ARDRONE_CONFIG_KEY_REF_a10(KEY, NAME, INI_TYPE, C_TYPE, C_TYPE_PTR, RW, RW_CUSTOM, DEFAULT, CALLBACK, CATEGORY) //do nothing for reference-only parameters
00044 #define ARDRONE_CONFIG_KEY_IMM_a10(KEY, NAME, INI_TYPE, C_TYPE, C_TYPE_PTR, RW, RW_CUSTOM, DEFAULT, CALLBACK, CATEGORY) { if(0!=strcmp(KEY,"custom") && ((RW & K_WRITE) != 0 || (RW_CUSTOM & K_WRITE) != 0)) LOAD_PARAM_NUM(NAME,C_TYPE, DEFAULT) } // parameters under the custom key are for control of application/user/session, we don't want to change these!
00045 #define ARDRONE_CONFIG_KEY_STR_a10(KEY, NAME, INI_TYPE, C_TYPE, C_TYPE_PTR, RW, RW_CUSTOM, DEFAULT, CALLBACK, CATEGORY) { if(0!=strcmp(KEY,"custom") && ((RW & K_WRITE) != 0 || (RW_CUSTOM & K_WRITE) != 0)) LOAD_PARAM_STR(NAME, DEFAULT) }
00046 
00047 #include <config_keys.h> // include the parameter definitions, which will be replaced by the above
00048 
00049 #undef LOAD_PARAM_NUM
00050 #undef LOAD_PARAM_STR
00051 #undef ARDRONE_CONFIG_KEY_IMM_a10
00052 #undef ARDRONE_CONFIG_KEY_REF_a10
00053 #undef ARDRONE_CONFIG_KEY_STR_a10
00054 
00055 // Now we delete any old configuration that we may have stored, this is so the profiles will be reinitialized to drone default before being updated with the potentially new set of custom parameters that we specify above.
00056 // We have to do this because only non-default parameters are sent, so if we delete a ros_param, the local parameter will be not be changed (above), thus will remain default and thus won't be updated on the drone - a problem if old profiles exist.
00057 
00058 char buffer[MULTICONFIG_ID_SIZE + 1];
00059 
00060 sprintf(buffer, "-%s", usr_id);
00061 printf("Deleting Profile %s\n", buffer);
00062 ARDRONE_TOOL_CONFIGURATION_ADDEVENT(profile_id, buffer, NULL);
00063 
00064 sprintf(buffer, "-%s", app_id);
00065 printf("Deleting Application %s\n", buffer);
00066 ARDRONE_TOOL_CONFIGURATION_ADDEVENT(application_id, buffer, NULL);
00067 
00068 #endif // SNIPPET_ROS_TO_ARDRONE_CONFIG_H


ardrone_autonomy
Author(s): Mani Monajjemi, Mani Monajjemi
autogenerated on Fri Aug 28 2015 10:07:51