Real Time Control of Crazyflie with ROS

Discussions about all things Bitcraze
Post Reply
burakhocaoglu
Beginner
Posts: 5
Joined: Wed Jun 06, 2018 1:34 pm

Real Time Control of Crazyflie with ROS

Post by burakhocaoglu » Tue Sep 04, 2018 9:14 pm

Hello there and sorry for the long post,

I've been working with Crazyflie2.0 platform for a while in a project and have a few questions. I am currently using the repo in the link https://github.com/wuwushrek/sim_cf/tre ... -uav-final with a bunch of my code on top of it.

To explain briefly, in my project I will control a swarm of crazyflies from a master computer which will work as a ground station. The ground station knows where each crazyflie is, where they are going at any moment, their path and various missions assigned to them and so on... During the execution of simulation, the crazyflies have risks of collision (since I did not use the planner of actual Crazyflie stack, I used OMPL). Consider them as that they are going on line segments, which are collision free against static obstacles but not against each other. My problem is at this point.

I've been observing how the motion commands were implemented in ROS and Python and through several experiments, I realized that ROS Services (in implementation of such as goTo or takeoff) are not preemptable. Even though I publish some messages to /cmd_hover for safety for a short instance to avoid crazyflieXcrazyflie collision and observe the crazyflie responds to it, right after executing that safety measure the crazyflie tries to reach its next goal/waypoint in its path more aggresively to make it in time, which is given by duration element of the corresponding ROS Service. I also tried to use /cmd_vel only, but it is a simulation oriented topic, so I guess its not a surprise that it did not work at all - they stood still despite continuous cmd_vel publishes.
  1. Is there any way for me to control multiple Crazyflies within ROS and Python stack in real time? I am running out of ideas currently.
  • There was a matlab file for human avoidance. I also watched the video of it in execution. The idea is to generate a repulsive force to avoid collision, right? How can I use that idea in Crazyflie ROS stack? Its a quite efficient idea.
  • I used OMPL in motion planning since it gives a more-or-less near optimal paths in a few seconds (per crazyflie), I may use its optimization structures but it puts a computational workload on the simulation and I am quite poor in terms of performance. In fact, in the actual crazyflie stack I cannot fly more than 2 crazyflies in SITL mode developed by wuwushrek in this forum. Thanks to his further modifications on SITL & Gazebo communication, I can fly 4 and sometimes more (if my pc is in good mood :D)
Thanks in advance and sorry again for the long post, I was trying to find a solution in deep.

whoenig
Expert
Posts: 290
Joined: Mon Oct 27, 2014 2:55 am

Re: Real Time Control of Crazyflie with ROS

Post by whoenig » Wed Sep 05, 2018 3:30 am

Hi,

The goTo and takeoff commands are "high-level" commands, which essentially means that the setpoint is computed on-board the Crazyflie. The setpoint can be temporarily overwritten by sending "low-level" commands such as the ones with cmd_hover or cmd_vel. Once you stop sending "low-level" commands, the high-level commands become active again (in other words: there is a priority where low-level commands have a higher priority). This was mostly implemented to allow human backup pilots even in autonomous mode.

That being said, it is not impossible to preempt high-level commands. Specifically, you can send a new high-level command and it will replace the old one. So if you mainly use goTo commands, you should use another goTo command to stop the execution of the current goTo command; you can, for example, goTo your current position (but give it some time to allow the onboard planner to plan a trajectory that is feasible).

A few other notes:
  • The human-avoidance demo was implemented on-board. It is not part of the latest official firmware anymore, but you can find it in older firmware versions on github. This is not trivial to do off-board, because of the limited communication bandwidth.
  • I have not tried the simulation you refer to myself yet, but in principle Gazebo can run slower than realtime. The design of SITL/HITL in wuwushrek repository uses different processes for Gazebo and SITL which makes this mode potentially problematic. In the CrazyS SITL implementation (see https://github.com/gsilano/CrazyS), the firmware is simply compiled as part of a Gazebo plugin, which should allow any number of robots without issues (but of course, running slower than real-time on a slower computer). I am not sure if CrazyS supports the high-level commands, though.
  • For collision-free planning, you might be interested in this paper: W. Hönig, J. A. Preiss, T. K. S. Kumar, G. S. Sukhatme, and N. Ayanian. "Trajectory Planning for Quadrotor Swarms", in IEEE Transactions on Robotics (T-RO), Special Issue Aerial Swarm Robotics, vol. 34, no. 4, pp. 856-869, August 2018. Pre-print available at http://act.usc.edu.

wydmynd
Beginner
Posts: 8
Joined: Thu Dec 06, 2018 9:25 am

Re: Real Time Control of Crazyflie with ROS

Post by wydmynd » Tue Jan 08, 2019 10:08 am

hello, following up on this topic, I currently use cmd_hover on Crazyflie 2.0 with flow deck, and no external position tracking.
I can control the Crazyflie using this command but it is much more stable when using it with position commands (currently using python cflib outside ROS).
The crazyflie_server also listens to a message named cmd_position which I could not find much documentation for , even in this forum.
I saw the "test high level.py" code which uses cf.goTo commands and enables "high level controller".

I am seeking clarification - what is the practical difference between these two methods? (cf.goto and cmd_position)
which one is recommended under ROS?
where can I find an article or documentation for using either one? I looked in the 2017 "Flying Multiple UAVs Using ROS" by Wolfgang H¨onig and Nora Ayanian but could only find reference to cmd_hover.

Thanks!
TS

whoenig
Expert
Posts: 290
Joined: Mon Oct 27, 2014 2:55 am

Re: Real Time Control of Crazyflie with ROS

Post by whoenig » Wed Jan 09, 2019 7:45 pm

Hi,
The article "Flying Multiple UAVs Using ROS" was originally written in 2016 and does not contain information about cmd_hover/cmd_position or goTo because those were developed afterwards. Unfortunately, there is no newer documentation right now.

cmd_position sets the current setpoint of the CF to the specified position. I guess this might be what the python cflib does, but you would need to share the exact python code for me to double check. In contrast, if you enable the high-level mode and goTo, the CF will compute a smooth trajectory starting from its current state (position, yaw, velocity, etc.) going to the position and stopping there. GoTo is, in principle, much more robust for larger step changes (far away goals), and can be used for more aggressive flight. GoTo also allows you to specify a desired arrival time, while cmd_position just lets the drone arrive based on the current PID gains.

In both cases, performance will be largely affected by the choice of the controller. For the high-level mode (and goTo), I recommend using the mellinger controller.

wydmynd
Beginner
Posts: 8
Joined: Thu Dec 06, 2018 9:25 am

Re: Real Time Control of Crazyflie with ROS

Post by wydmynd » Sun Jan 13, 2019 10:34 am

thanks very much for the detailed reply!
I will share results when available.

Post Reply