robotika / katarina

Parrot drone Bebop
MIT License
75 stars 33 forks source link

Moving in a Direction During Key Press? #11

Closed NarimaanV closed 7 years ago

NarimaanV commented 7 years ago

Hi, This isn't an issue as it is a coding question in implementing this repository (fantastic repository by the way) for a school project. The project is basically that we have to turn our laptops into remote controls for a bebop drone. I've managed taking off and landing, now I'm left with the basic movements. During the press of a key, the drone has to move in a direction then stop when the key is lifted. My question is, is the following added in bebop.py enough to accomplish that? (based loosely on the flyToAltitude function):

def flyForward(self):
        speed = 20
        assert self.altitude is not None
        self.update(movePCMDCmd(True, 0, speed, 0, 0))

I have the system setup to take single character inputs and to call that function if a certain key is pressed or keep calling that function as long as the key is held down. The only thing I'm not sure of is, will the drone stop moving once I let go or do I need to add "self.update(movePCMDCmd(True, 0, 0, 0, 0))" to the end of that function so that after every call it tries returning to hovering? Appreciate any help!

al3Co commented 7 years ago

Please, review the code in the fork: https://github.com/al3Co/BebopDrone The codes: z_MoveBy.py z_MoveSpeed.by

NarimaanV commented 7 years ago

So once a single call of self.update(movePCMDCmd(True, 0, speed, 0, 0)) is made, the drone would keep moving forward until a call to self.update(movePCMDCmd(True, 0, 0, 0, 0)) is made? The update function would NOT return to hovering by itself?

al3Co commented 7 years ago

In the self.update(movePCMDCmd(True,0,0,0,0)) the boolean data is for hovering, you can move the drone by yaw movements and keep the hovering by giving it on false, when you change this data to true the drone looses the "hovering" property, to move the drone to one or more directions (forward-backward-left-right) you need the "true" data on it. If you are only moving the drone on Yaw, you can leave on "false" or if you need just float (hover), use: self.update(movePCMDCmd(False,0,0,0,0)) command.

NarimaanV commented 7 years ago

I see, that makes sense. Thanks for your help!

CE93Geek commented 7 years ago

@al3Co Hi, when I read your answer I felt the need to ask you about the issue I'm having with the "hover" function. I'm trying to implement a flight plan and I want the drone to hover in it's place after flying to certain altitude, so here is the code I wrote for hovering: robot.takeoff() robot.flyToAltitude( 2.0 ) for i in xrange(100): robot.hover() robot.land() where the hover() function contains the following update : self.update( cmd=movePCMDCmd( active=True, roll=0, pitch=0, yaw=0, gaz=0 ) ) but the drone tends to drift and moves around rather that hovering in its place. Then I understood from your answer that I should write it as self.update( cmd=movePCMDCmd( active=True, roll=0, pitch=0, yaw=0, gaz=0 ) ) for once and then change the flag to false in the loop as: for i in xrange(100): self.update( cmd=movePCMDCmd( active=False, roll=0, pitch=0, yaw=0, gaz=0 ) ) I'm I correct?

al3Co commented 7 years ago

Correct!

Please review: https://github.com/al3Co/BebopDrone/blob/master/core/bebop.py line: 195

def hover( self ):
        self.update( cmd=movePCMDCmd( active=False, roll=0, pitch=0, yaw=0, gaz=0 ) ) #Modified
CE93Geek commented 7 years ago

@al3Co Thank you so much! I tried the code today and the hover functionality was much more stable than before.

al3Co commented 7 years ago

I am glad to read that.