Read control inputs from mobile application

Firmware/software/electronics/mechanics
volmen3
Beginner
Posts: 11
Joined: Sat Nov 30, 2019 12:21 pm

Read control inputs from mobile application

Post by volmen3 »

Hello!

I'm trying to implement a controller for the Crazyflie and need to read user (pilot) inputs (from mobile application). My aim is to read this inputs and convert/transform them into other values (eg. change of the value range, sign etc.) and pass them to the control algorithm.

The question is: how do I read those inputs? Which function is responsible for that?

Second question on top of the first one:
As I need to be able to input velocity through the mobile app, how do I do that? My idea was to convert somehow the user input to velocity, but is there some other way where I can get my velocity from the app in form of "setpoint->velocity.x" for example? This should be my reference velocity...

Thank you in advance!
volmen3
Beginner
Posts: 11
Joined: Sat Nov 30, 2019 12:21 pm

Re: Read control inputs from mobile application

Post by volmen3 »

Any ideas? :)
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: Read control inputs from mobile application

Post by kimberly »

Hi and sorry for the late reply.

So currently I can not answer this but I diverted the question to @arnaud and @thefred. Unless you already found the answer yourself it the code?
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Read control inputs from mobile application

Post by kristoffer »

I'm don't fully understand what you want to do here and some clarifications would be helpful to get us on the right track.
Which part of the code are you looking at? Are you on Android or IOS?
When you mention controller, do you mean a controller as in the Crazyflie firmware control loop, or a mobile app?
volmen3
Beginner
Posts: 11
Joined: Sat Nov 30, 2019 12:21 pm

Re: Read control inputs from mobile application

Post by volmen3 »

Hello and thank you for your response!

I don't want to confuse you further :D , so I'll reformulate my question a bit and redefine goals I try to achieve...

I am implementing a position and a velocity controller for the Crazyflie and wish to have an easy way to provide reference position/velocity values to my Crazyflie. As I need to log data while providing these reference values, I probably have to use Linux/Windows client application with a connected PS3/other controller to my PC (so don't consider Android/iOS app for know).

My controller uses setpoint->velocity and setpoint->position structs to get reference values. My question is: How do I send those setpoints to the Crazyflie with my PS3 controller?

Right know when I use my PS3 cotroller I am able to command setpoint->thrust setpoint->attitude.roll, setpoint->attitude.pitch, and setpoint->attitudeRate.yaw. So basically I ask, how can I change current inputs to setpoint->velocity.x, setpoint->velocity.y, setpoint->velocity.z OR setpoint->position.x, setpoint->position.y, setpoint->position.z?

Best regards!
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: Read control inputs from mobile application

Post by kimberly »

Hi,

So if you look at the cfclient, the chosen setpoint is depended on the 'Assist mode'. Currently yours is set on 'attitude mode' (angle setpoints) but you can also set it to position hold, which will actually give velocity setpoints to the crazyflie.

But you might need to consider to make your own python script that reads out the input of your PS3 controller and sets those setpoints as a respond to that, while doing the logging in the main time. Have you looked at the example scripts yet from the crazyflie-lib-python ? (https://github.com/bitcraze/crazyflie-l ... r/examples). In cflib/motion_commander.py you can also find the functions for setting velocity setpoints so you can use that. How to read out ps3 controller input is something that you can either find online or can dig out of how we do it in the client.
volmen3
Beginner
Posts: 11
Joined: Sat Nov 30, 2019 12:21 pm

Re: Read control inputs from mobile application

Post by volmen3 »

Hey, thanks for the reply!

You write: "you can also set it to position hold, which will actually give velocity setpoints to the crazyflie". But how do I set those setpoints (keyboard, PS3-Controller)?

I looked at the "motion_commander.py" script and unfortunately it doesn't really help me, because I have to provide those setpoints online and not in a predefined manner.

I've also got two questions:

1) I kind of solved the problem partially by mapping current PS3-Controller inputs (setpoint->roll, pitch, thrust) to three different variables of my reference velocity. But I have a problem with the thrust input: The values are only in the positive range, but I would like to be able to also input negative values for thrust (e.g. by moving joystick from the midpoint backwards). How to achieve it?

2) May be you have another suggestion how can one using PS3-Controller provide three different values to the Crazyflie in the range lets say from -1 to 1 (the range itself isn't important, important is, that it contains negative and positive domains)?

Thanks in advance!
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Read control inputs from mobile application

Post by kristoffer »

Hi!
You write: "you can also set it to position hold, which will actually give velocity setpoints to the crazyflie". But how do I set those setpoints (keyboard, PS3-Controller)?
Just use a game pad. In position hold mode, the client will send velocity setpoints when you move the sticks.

You can find the code that sends the setpoints in the client https://github.com/bitcraze/crazyflie-c ... #L250-L263

The corresponding implementation in the python lib is here https://github.com/bitcraze/crazyflie-l ... mmander.py
1) I kind of solved the problem partially by mapping current PS3-Controller inputs (setpoint->roll, pitch, thrust) to three different variables of my reference velocity. But I have a problem with the thrust input: The values are only in the positive range, but I would like to be able to also input negative values for thrust (e.g. by moving joystick from the midpoint backwards). How to achieve it?
If you have special needs for your setpoints that are currently not supported, you can either modify the client to send another type of setpoint or modify the Crzyflie firmware to add/remove an offset.

It is alos possible to extend the system with a new type of setpoint for your needs if you like.

Unfortunately, if I remember correctly, the code for setpoint handling (both in the client and Crazyflie FW) might be a bit messy .
volmen3
Beginner
Posts: 11
Joined: Sat Nov 30, 2019 12:21 pm

Re: Read control inputs from mobile application

Post by volmen3 »

Thank you for the help!

I have managed to configure the "Assist Mode", but now I am facing a very strange behavior in the "Position Hold" mode:

The "Assist Mode" is configured to be one of the shoulder buttons of my PS3-Controller. I also log "setpoint->velocity.x/y/z" variables to see if it is actually happening something when I move sticks. And indeed, when logging all 3 variables I see them on the Plotter.

I also configured my setpoint->velocity.z to be kind of "thrust", so when I increase it while holding the "Assist Mode" button, I expect motors to rotate. But it works in a very strange way: motors begin to rotate after I release the button and they hold the rotation rate which corresponds to the last stick deflection when the button was released. For example:

1) A press "Assist mode" button and hold it
2) I move the stick (which corresponds to setpoint->velocity.z) back and forth and see corresponding output on the Plotter, but nothing is transmitted to the motors.
3) Now I release the "Assist mode" button while holding the stick in lets say 20% deflection and motors start to rotate with 20% of the max. rotational rate.
4) I release the stick, motors still rotate
5) I press "Assist mode" button with the stick in 0% deflection and motors stop.
6) Now I can repeat the same, but this time release "Assist mode" button while holding the stick in 70% deflection, and motors will rotate with 70% of the max. rotational rate ans so on...

So, motors get the signal with a new value exactly at the moment when "Assist mode" button is released...

Do you have any idea what could be the reason of that problem and how to solve it?

Best regards
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: Read control inputs from mobile application

Post by kimberly »

This is indeed a weird phenomenon so I believe you have met a corner case. Usually we just press the assist button once and after that start controlling it. It is probably just a bug somewhere.... but it will take time to find it.

We should probably make an Github issue out of this on https://github.com/bitcraze/crazyflie-clients-python and recreate your problem
Post Reply