A question about 'modeDisable', 'modeAbs' and 'modeVelocity'

Firmware/software/electronics/mechanics
Post Reply
linlin2017
Beginner
Posts: 16
Joined: Tue Oct 17, 2017 2:05 am

A question about 'modeDisable', 'modeAbs' and 'modeVelocity'

Post by linlin2017 »

Hi developers,
I have a question about the source code of crazyflie 2.0. In the stabilizer_types.h file, what 'modeDisable', 'modeAbs' and 'modeVelocity' mean?
Thanks. :)
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: A question about 'modeDisable', 'modeAbs' and 'modeVelocity'

Post by tobias »

Those should clearly be documented better and quite a bit of legacy involved. :oops:

The enum describes what stabilization controllers should be activated for what axis.

To get some idea how to use it look in crtp_commander_rpyt.c
linlin2017
Beginner
Posts: 16
Joined: Tue Oct 17, 2017 2:05 am

Re: A question about 'modeDisable', 'modeAbs' and 'modeVelocity'

Post by linlin2017 »

tobias wrote: Thu Nov 02, 2017 11:04 am Those should clearly be documented better and quite a bit of legacy involved. :oops:

The enum describes what stabilization controllers should be activated for what axis.

To get some idea how to use it look in crtp_commander_rpyt.c
Thank you.
Could you tell me your ideas of attitude control and position control in the source code. Because I can't deduce your control ideas through the source code. Thank you.
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: A question about 'modeDisable', 'modeAbs' and 'modeVelocity'

Post by tobias »

In attitude control the controller will try to follow the desired set angle for roll, pitch and yaw. In position control it will instead try to go to and keep the desired position. This though requires some kind of position information.

Maybe you can share a bit what you would like to achieve. Then it will be easier for me to help.
linlin2017
Beginner
Posts: 16
Joined: Tue Oct 17, 2017 2:05 am

Re: A question about 'modeDisable', 'modeAbs' and 'modeVelocity'

Post by linlin2017 »

tobias wrote: Mon Nov 06, 2017 12:29 pm In attitude control the controller will try to follow the desired set angle for roll, pitch and yaw. In position control it will instead try to go to and keep the desired position. This though requires some kind of position information.

Maybe you can share a bit what you would like to achieve. Then it will be easier for me to help.
Thank you. I want to test a attitude stabilization algorithm that have three reference inputs, three real-time state inputs and three control outputs. The three reference inputs are roll, pitch and yaw angles we want. The three real-time state inputs, which act as feedback inputs, are real-time roll, pitch and yaw angles of aircraft body. The three outputs are three moments controlling the attitude of aircraft. In the control outputs of the algorithm, there is no thrust for the vertical moment of aircraft. And the experiment of testing the algorithm could be operated on a spherical joint. How should I modify the source code? Thank you. :)
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: A question about 'modeDisable', 'modeAbs' and 'modeVelocity'

Post by kristoffer »

You can find the main control loop in

Code: Select all

stabilizerTask()
in stablizer.c.

The first part is about getting and understanding the current state of the system (the actual position, pitch, roll, yaw and so on) and the desired state (the wanted position and/or roll, pitch, yaw).

Code: Select all

    getExtPosition(&state);
    stateEstimator(&state, &sensorData, &control, tick);

    commanderGetSetpoint(&setpoint, &state);
Then we try to calculate what to do to get from the current state to the desired state in

Code: Select all

    stateController(&control, &setpoint, &sensorData, &state, tick);
Finally the output of the controller is used to control the power for the motors in

Code: Select all

      powerDistribution(&control);


The state variable describes the current state,
the setpoint variable describes the desired state and
the control variable contains data of how to power the motors.

The

Code: Select all

stateController()
is implemented in controller_pid.c and this is probably the area you want to work on. One option is to add your own controller in a new c file to make it easy to switch back and forth.
linlin2017
Beginner
Posts: 16
Joined: Tue Oct 17, 2017 2:05 am

Re: A question about 'modeDisable', 'modeAbs' and 'modeVelocity'

Post by linlin2017 »

kristoffer wrote: Fri Nov 10, 2017 10:09 am You can find the main control loop in

Code: Select all

stabilizerTask()
in stablizer.c.

The first part is about getting and understanding the current state of the system (the actual position, pitch, roll, yaw and so on) and the desired state (the wanted position and/or roll, pitch, yaw).

Code: Select all

    getExtPosition(&state);
    stateEstimator(&state, &sensorData, &control, tick);

    commanderGetSetpoint(&setpoint, &state);
Then we try to calculate what to do to get from the current state to the desired state in

Code: Select all

    stateController(&control, &setpoint, &sensorData, &state, tick);
Finally the output of the controller is used to control the power for the motors in

Code: Select all

      powerDistribution(&control);


The state variable describes the current state,
the setpoint variable describes the desired state and
the control variable contains data of how to power the motors.

The

Code: Select all

stateController()
is implemented in controller_pid.c and this is probably the area you want to work on. One option is to add your own controller in a new c file to make it easy to switch back and forth.
Thank you very much. Before adding my own attitude controller, I want to figure out the current algorithm in the source code. I have a question to ask you. In the source code blew:

Code: Select all

typedef struct setpoint_s {
  uint32_t timestamp;

  attitude_t attitude;
  attitude_t attitudeRate;
  float thrust;
  point_t position;
  velocity_t velocity;

  struct {
    mode_t x;
    mode_t y;
    mode_t z;
    mode_t roll;
    mode_t pitch;
    mode_t yaw;
  } mode;
} setpoint_t;
why to define the struct mode in the struct setpoint? Why does mode.x have three mode? why do mode.y, mode.z, mode.roll and so on? Thank you.
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: A question about 'modeDisable', 'modeAbs' and 'modeVelocity'

Post by kristoffer »

I think that the use of the setpoint_t has been added to over time, and it has become a bit messy. It could probably be improved :-)

The idea is that the setpoint_t describes the desired state of the system, and this include:
* absolute roll/pitch/yaw as used in the standard "manual" flying mode
* roll/pitch/yaw in rate mode as used by some advanced pilots
* a position (x,y,z) to go to, used with absolute positioning systems such as LPS
* a velocity or rate change for x, y, z or roll, pitch, yaw as used with the flow deck

In some cases you want the desired state to be an absolute position or roll angle for instance, while in other cases you are interested in describing a rate of change or velocity. It must also be possible to tell the controller that one parameter of the setpoint is important while another should be ignored.
This is where the mode comes in:
* modeDisable - ignore this paramater
* modeAbs - the desired state is an absolute value
* modeVelocity - the desired state is a rate (or velocity)

Depending on the mode of a parameter, the controller will use different fields in the setpoint_t to get the actual value (setpoint.attitude, setpoint.attitudeRate and so on)

By the way, I can see that you are not on the latest version of the firmware source code. The mode_t struct was renamed to stab_mode_t in June.
linlin2017
Beginner
Posts: 16
Joined: Tue Oct 17, 2017 2:05 am

Re: A question about 'modeDisable', 'modeAbs' and 'modeVelocity'

Post by linlin2017 »

kristoffer wrote: Mon Nov 13, 2017 1:47 pm I think that the use of the setpoint_t has been added to over time, and it has become a bit messy. It could probably be improved :-)

The idea is that the setpoint_t describes the desired state of the system, and this include:
* absolute roll/pitch/yaw as used in the standard "manual" flying mode
* roll/pitch/yaw in rate mode as used by some advanced pilots
* a position (x,y,z) to go to, used with absolute positioning systems such as LPS
* a velocity or rate change for x, y, z or roll, pitch, yaw as used with the flow deck

In some cases you want the desired state to be an absolute position or roll angle for instance, while in other cases you are interested in describing a rate of change or velocity. It must also be possible to tell the controller that one parameter of the setpoint is important while another should be ignored.
This is where the mode comes in:
* modeDisable - ignore this paramater
* modeAbs - the desired state is an absolute value
* modeVelocity - the desired state is a rate (or velocity)

Depending on the mode of a parameter, the controller will use different fields in the setpoint_t to get the actual value (setpoint.attitude, setpoint.attitudeRate and so on)

By the way, I can see that you are not on the latest version of the firmware source code. The mode_t struct was renamed to stab_mode_t in June.
Thank you very much. Then I downloaded the latest version of the firmware source code, and replaced the old one in the 'projects' file in VM desktop with the latest one. When I click the hammer icon to build the project, the console shows the message:

10:41:28 **** Build of configuration Default for project crazyflie-firmware ****
make all
ERROR: One or more of the git submodules are not initialized. Try
git submodule init
git submodule update
make: *** [check_submodules] Error 255

10:41:29 Build Finished (took 1s.212ms)

And when I flash using radio, the console shows the message:

10:43:43 **** Build of configuration Default for project crazyflie-firmware ****
make cload
python3 -m cfloader flash cf2.bin stm32-fw
Restart the Crazyflie you want to bootload in the next
10 seconds ...
done!
Connected to bootloader on Crazyflie 2.0 (version=0x10)
Target info: nrf51 (0xFE)
Flash pages: 232 | Page size: 1024 | Buffer pages: 1 | Start page: 88
144 KBytes of flash available for firmware image.
Target info: stm32 (0xFF)
Flash pages: 1024 | Page size: 1024 | Buffer pages: 10 | Start page: 16
1008 KBytes of flash available for firmware image.
Traceback (most recent call last):
File "/home/bitcraze/projects/crazyflie-clients-python/src/cfloader/__init__.py", line 179, in main
bl.flash(filename, targetnames)
File "/home/bitcraze/projects/crazyflie-lib-python/cflib/bootloader/__init__.py", line 191, in flash
f = open(filename, 'rb')
FileNotFoundError: [Errno 2] No such file or directory: 'cf2.bin'
[Errno 2] No such file or directory: 'cf2.bin'

10:43:46 Build Finished (took 3s.499ms)

I suspect that the way of replacing the old version of firmware source code is wrong. Could you tell me the proper way? Thank you.
Post Reply