-
Notifications
You must be signed in to change notification settings - Fork 56
Creating a new recconect app and updating CF firmware to newer version #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
apps/crazyflie_position_publisher_reconnection/app-colcon.meta
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "names": { | ||
| "rmw_microxrcedds": { | ||
| "cmake-args": [ | ||
| "-DRMW_UXRCE_TRANSPORT=custom_serial", | ||
| "-DRMW_UXRCE_MAX_NODES=1", | ||
| "-DRMW_UXRCE_MAX_PUBLISHERS=2", | ||
| "-DRMW_UXRCE_MAX_SUBSCRIPTIONS=0", | ||
| "-DRMW_UXRCE_MAX_SERVICES=0", | ||
| "-DRMW_UXRCE_MAX_CLIENTS=0", | ||
| "-DRMW_UXRCE_MAX_HISTORY=1", | ||
| "-DRMW_UXRCE_XML_BUFFER_LENGTH=400" | ||
| ] | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| /*FreeRtos includes*/ | ||
| #include "FreeRTOS.h" | ||
| #include "task.h" | ||
|
|
||
| #include <rcl/rcl.h> | ||
| #include <geometry_msgs/msg/point32.h> | ||
| #include "example_interfaces/srv/add_two_ints.h" | ||
| #include <geometry_msgs/msg/twist.h> | ||
|
|
||
| #include <rcutils/allocator.h> | ||
|
|
||
| #include "config.h" | ||
| #include "log.h" | ||
| #include "crc.h" | ||
| #include "worker.h" | ||
| #include "num.h" | ||
| #include "debug.h" | ||
| #include "radiolink.h" | ||
| #include <time.h> | ||
|
|
||
| #include "microrosapp.h" | ||
|
|
||
| #define RCCHECK(msg) if((rc != RCL_RET_OK)){DEBUG_PRINT("Failed status on line %d: %d. Aborting.\n",__LINE__,(int)rc); goto clean;} | ||
| #define RCSOFTCHECK(msg) if((rc != RCL_RET_OK)){DEBUG_PRINT("Failed status on line %d: %d. Continuing.\n",__LINE__,(int)rc);} | ||
|
|
||
| static int pitchid, rollid, yawid; | ||
| static int Xid, Yid, Zid; | ||
|
|
||
| float sign(float x){ | ||
| return (x >= 0) ? 1.0 : -1.0; | ||
| } | ||
|
|
||
| void appMain(){ | ||
| while(1){ | ||
| absoluteUsedMemory = 0; | ||
| usedMemory = 0; | ||
|
|
||
| // ####################### RADIO INIT ####################### | ||
|
|
||
| int radio_connected = logGetVarId("radio", "isConnected"); | ||
|
|
||
| while(!logGetUint(radio_connected)) vTaskDelay(100); | ||
| DEBUG_PRINT("Radio connected\n"); | ||
|
|
||
| // ####################### MICROROS INIT ####################### | ||
|
|
||
| DEBUG_PRINT("Free heap pre uROS: %d bytes\n", xPortGetFreeHeapSize()); | ||
| vTaskDelay(50); | ||
|
|
||
| rcl_context_t context; | ||
| rcl_init_options_t init_options; | ||
| rcl_ret_t rc; | ||
| rcl_ret_t rc_aux __attribute__((unused)); | ||
|
|
||
| init_options = rcl_get_zero_initialized_init_options(); | ||
| rcl_allocator_t freeRTOS_allocator = rcutils_get_zero_initialized_allocator(); | ||
| freeRTOS_allocator.allocate = __crazyflie_allocate; | ||
| freeRTOS_allocator.deallocate = __crazyflie_deallocate; | ||
| freeRTOS_allocator.reallocate = __crazyflie_reallocate; | ||
| freeRTOS_allocator.zero_allocate = __crazyflie_zero_allocate; | ||
|
|
||
| if (!rcutils_set_default_allocator(&freeRTOS_allocator)) { | ||
| DEBUG_PRINT("Error on default allocators (line %d)\n",__LINE__); | ||
| vTaskSuspend( NULL ); | ||
| } | ||
|
|
||
| rc = rcl_init_options_init(&init_options, rcutils_get_default_allocator()); | ||
| RCCHECK() | ||
|
|
||
| context = rcl_get_zero_initialized_context(); | ||
|
|
||
| rc = rcl_init(0, NULL, &init_options, &context); | ||
| RCCHECK() | ||
|
|
||
| rc = rcl_init_options_fini(&init_options); | ||
|
|
||
| rcl_node_t node = rcl_get_zero_initialized_node(); | ||
| rcl_node_options_t node_ops = rcl_node_get_default_options(); | ||
|
|
||
| rc = rcl_node_init(&node, "crazyflie_node", "", &context, &node_ops); | ||
| RCCHECK() | ||
|
|
||
| // Create publisher 1 | ||
| const char* drone_odom = "/drone/odometry"; | ||
|
|
||
| rcl_publisher_t pub_odom = rcl_get_zero_initialized_publisher(); | ||
| const rosidl_message_type_support_t * pub_type_support_odom = ROSIDL_GET_MSG_TYPE_SUPPORT(geometry_msgs, msg, Point32); | ||
| rcl_publisher_options_t pub_opt_odom = rcl_publisher_get_default_options(); | ||
| pub_opt_odom.qos.reliability = RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT; | ||
|
|
||
|
|
||
| rc = rcl_publisher_init( | ||
| &pub_odom, | ||
| &node, | ||
| pub_type_support_odom, | ||
| drone_odom, | ||
| &pub_opt_odom); | ||
|
|
||
| if(rc != RCL_RET_OK){ | ||
| rc_aux = rcl_node_fini(&node); | ||
| } | ||
| RCCHECK() | ||
|
|
||
| // Create publisher 2 | ||
| const char* drone_attitude = "/drone/attitude"; | ||
|
|
||
| rcl_publisher_t pub_attitude = rcl_get_zero_initialized_publisher(); | ||
| const rosidl_message_type_support_t * pub_type_support_att = ROSIDL_GET_MSG_TYPE_SUPPORT(geometry_msgs, msg, Point32); | ||
| rcl_publisher_options_t pub_opt_att = rcl_publisher_get_default_options(); | ||
| pub_opt_att.qos.reliability = RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT; | ||
|
|
||
| rc = rcl_publisher_init( | ||
| &pub_attitude, | ||
| &node, | ||
| pub_type_support_att, | ||
| drone_attitude, | ||
| &pub_opt_att); | ||
|
|
||
| if(rc != RCL_RET_OK){ | ||
| rc_aux = rcl_publisher_fini(&pub_odom, &node); | ||
| rc_aux = rcl_node_fini(&node); | ||
| } | ||
| RCCHECK() | ||
|
|
||
| // Init messages | ||
| geometry_msgs__msg__Point32 pose; | ||
| geometry_msgs__msg__Point32__init(&pose); | ||
| geometry_msgs__msg__Point32 odom; | ||
| geometry_msgs__msg__Point32__init(&odom); | ||
|
|
||
| //Get pitch, roll and yaw value | ||
| pitchid = logGetVarId("stateEstimate", "pitch"); | ||
| rollid = logGetVarId("stateEstimate", "roll"); | ||
| yawid = logGetVarId("stateEstimate", "yaw"); | ||
|
|
||
| //Get X,Y and Z value | ||
| Xid = logGetVarId("stateEstimate", "x"); | ||
| Yid = logGetVarId("stateEstimate", "y"); | ||
| Zid = logGetVarId("stateEstimate", "z"); | ||
|
|
||
| DEBUG_PRINT("Free heap post uROS configuration: %d bytes\n", xPortGetFreeHeapSize()); | ||
| DEBUG_PRINT("uROS Used Memory %d bytes\n", usedMemory); | ||
| DEBUG_PRINT("uROS Absolute Used Memory %d bytes\n", absoluteUsedMemory); | ||
|
|
||
| // ####################### MAIN LOOP ####################### | ||
|
|
||
| // static P2PPacket pk; | ||
| // pk.port = 0; | ||
| // pk.size = 11; | ||
| // memcpy(pk.data, "Hello World", 11); | ||
| // radiolinkSendP2PPacketBroadcast(&pk); | ||
|
|
||
| radiolinkSetPowerDbm(-50); | ||
|
|
||
| while(logGetUint(radio_connected)){ | ||
|
|
||
| pose.x = logGetFloat(pitchid); | ||
| pose.y = logGetFloat(rollid); | ||
| pose.z = logGetFloat(yawid); | ||
| odom.x = logGetFloat(Xid); | ||
| odom.y = logGetFloat(Yid); | ||
| odom.z = logGetFloat(Zid); | ||
|
|
||
| // Debug | ||
| // int radio_rssi = logGetVarId("radio", "rssi"); | ||
| // odom.x = logGetFloat(radio_rssi); | ||
| // odom.y = xPortGetFreeHeapSize(); | ||
|
|
||
| rc = rcl_publish( &pub_attitude, (const void *) &pose, NULL); | ||
| RCSOFTCHECK() | ||
|
|
||
| rc = rcl_publish( &pub_odom, (const void *) &odom, NULL); | ||
| RCSOFTCHECK() | ||
|
|
||
| vTaskDelay(10/portTICK_RATE_MS); | ||
| } | ||
|
|
||
| rc = rcl_publisher_fini(&pub_odom, &node); | ||
| rc = rcl_publisher_fini(&pub_attitude, &node); | ||
| rc = rcl_node_fini(&node); | ||
| clean: | ||
| rc = rcl_shutdown(&context); | ||
| DEBUG_PRINT("Connection lost, retriying\n"); | ||
| } | ||
|
|
||
| vTaskSuspend( NULL ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.