Setting parameters via terminal [ROS]

Firmware/software/electronics
Post Reply
aesreal
Beginner
Posts: 22
Joined: Thu Mar 08, 2018 6:34 am

Setting parameters via terminal [ROS]

Post by aesreal »

Hi all,

Is there an already built-in method to change crazyflie parameters using rosrun on terminal?

Have searched through crazyflie_tools and there doesn't seem to be executable that can do it (the closest one is listParams), so I tried to write my own executable for it (I do not know C++ at all, was just playing around and trying it out, am taking online courses right now.), which compiled but doesn't work.

I'm guessing it's the following block of code here that would make it work: https://github.com/whoenig/crazyflie_cp ... #L770-L775

I was hoping to use this command line to control the parameters for the crazyflies because I'm using more than one, it would be so much faster to change all of their parameters by a using a single line of code.

For instance, maybe something like:
rosrun crazyflie_tools setParam --ring.effect -- 2 --uri radio://0/100/2M/E7E7E7E7XX
or
rosrun crazyflie_tools setParam --param ring.effect --value 2 --uri radio://0/100/2M/E7E7E7E7XX
or
rosrun crazyflie_tools setParam --param ring/effect --value 2 --uri radio://0/100/2M/E7E7E7E7XX

I've tried using the python way of connecting at first. It works well, but the issue is that using crazyflie.open_link(uri) takes a considerable amount of time (>2s) and it establishes a blocking connection, whereas using the crazyflie ros tools, multiple crazyfliess can be targeted at once (not sure why that is so, might be because packets are sent instead of a establishing a stable link). I might as well do it via cfclient if I'm using this method.

Here is what I did, if anyone is interested. I'm ashamed because I really don't know what I'm doing, not sure if what I'm passing into the method even makes sense.

This is based of listParams.cpp by whoenig's crazyflie ros
setParam.cpp

Code: Select all

#include <iostream>

#include <boost/program_options.hpp>
#include <crazyflie_cpp/Crazyflie.h>

int main(int argc, char **argv)
{

  std::string uri;
  std::string defaultUri("radio://0/80/2M/E7E7E7E7E7");
  std::uint8_t param;
  std::string value;

  namespace po = boost::program_options;

  po::options_description desc("Allowed options");
  desc.add_options()
    ("help", "produce help message")
    ("uri", po::value<std::string>(&uri)->default_value(defaultUri), "unique ressource identifier")
    ("param", po::value<std::uint8_t>(&param)->required(), "parameter to set")
    ("value", po::value<std::string>(&value)->required(), "value to set")
  ;

  try
  {
    po::variables_map vm;
    po::store(po::parse_command_line(argc, argv, desc), vm);
    po::notify(vm);

    if (vm.count("help")) {
      std::cout << desc << "\n";
      return 0;
    }
  }
  catch(po::error& e)
  {
    std::cerr << e.what() << std::endl << std::endl;
    std::cerr << desc << std::endl;
    return 1;
  }

  try
  {
    Crazyflie cf(uri);
    cf.setParam(param, value);

    return 0;
  }
  catch(std::exception& e)
  {
    std::cerr << e.what() << std::endl;
    return 1;
  }
}
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: Setting parameters via terminal [ROS]

Post by whoenig »

This would be indeed a great addition - feel free to open an issue in the crazyflie_tools repository and I can take a look.

The code will be a bit more complicated, because it would need to handle different data types, e.g., here is how I do it in `crazyflie_ros`: https://github.com/whoenig/crazyflie_ro ... #L284-L310.

All crazyflie_tools use a point-to-point communication right now, so changing parameters in parallel won't be possible; In the crazyswarm project we have python scripts that run crazyflie_tools in a loop for each CF. It would be possible to change parameters using broadcasts, but that is not implemented yet.

As for the difference between crazyflie_cpp and the python client: crazyflie_cpp does not have the notion of a connection like the python client, but individual commands might fail if a timeout is reached. Additionally, the communication is optimized to hide firmware latency of the asynchronous communication. You can establish a connection with crazyflie_cpp in <1s.
aesreal
Beginner
Posts: 22
Joined: Thu Mar 08, 2018 6:34 am

Re: Setting parameters via terminal [ROS]

Post by aesreal »

Thanks for the elaboration! That cleared my doubts

I am using the awesome chooser.py that you made and wanted to expand on it to be able to control lights/led rings for now, so it got me thinking why not expand it to be able to change parameters too?

Opened the issue here!: https://github.com/whoenig/crazyflie_ros/issues/98

I guess CFClient is built for stability, steady flights, statistics, and configuration/maintenance, whereas crazyflie_cpp is made more for controlling multiple drones, faster communication, each has their pros and cons.
Post Reply