I had idea of controlling drone without a real RC Remote control hardware. We have done some work but have got stuck at a place where we are unable to find a way ahead.
We tried to make a small android app to control a drone using a virtual joystick like widget in the android app, similar to many racing games which have a joystick on screen for turning to different direction. I have installed the drone kit API in an android project/Cloned the Tower code from github.
I am planning to do it by sending virtual commands to drone. The commands will be similar to the commands sent from a RC remote control hardware. We need to put the drone in manual mode then we can send the virtual commands.
I have written the commands as follows.
- Created two methods, one for enabling virtualstick in Drone kit Control API, and one method to send the desired commands to drone.
- Call enableVirtualStick() method for enabling the joystick mode.
- Once the joystick mode is enabled, call sendVirtualStickCommands(5,0,5) method to send a command to the drone.
But the result is that enableVirtualStick() is successfully executed but sendVirtualCommands methods results in error callback from the dronekit API. The onError call back is received everytime a call is made.
public void enableVirtualStick(){
if(getDrone().isConnected()){
ControlApi.getApi(getDrone()).enableManualControl(true, new ControlApi.ManualControlStateListener() {
@Override
public void onManualControlToggled(boolean isEnabled) {
if(isEnabled){
Log( "Joystick Mode Enabled”);
}else{
Log( “Could not enable Joystick Mode”);
}
}
});
} else {
Log( "No Vehicle is connected”);
}
}
Whenever the joystick is moved , this method is called with the parameters being sent depending on the direction and intensity of joystick movement.
sendVirtualStickCommands(5,0,5);
public void sendVirtualStickCommands(float pitch_val, float roll_val, float throttle_val ){
ControlApi.getApi(getDrone()).manualControl(pitch_val,roll_val,throttle_val, new AbstractCommandListener() {
@Override
public void onSuccess() {
Log(“Joystick command accepted by vehicle”);
}
@Override
public void onError(int i) {
Log( “Error in Joystick”);
// It always shows this error
}
@Override
public void onTimeout() {
Log( "Joystick command timed out”);
}
});
}
I also tried to send the following command, but it results in nothing.
msg_rc_channels_override rc_override = new msg_rc_channels_override();
rc_override.chan1_raw = 1000 //right; 2000 //left
rc_override.chan3_raw = 1000 //back; 2000 //forward
rc_override.target_system = 0;
rc_override.target_component = 0;
ExperimentalApi.getApi(mDrone).sendMavlinkMessage(new MavlinkMessageWrapper(rc_override));
Since there is not much information in the logs, it is hard to understand what is going inside the Dronekit API, so We are unable to find a way out.
If you can help in our activity/show a way where to look for more info that will be really appreciated.
A very very thank you for spending your time to read my message.
Best Regards