Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird behavior with 'hover()' #69

Open
OdedHorowits opened this issue Jul 8, 2024 · 9 comments
Open

Weird behavior with 'hover()' #69

OdedHorowits opened this issue Jul 8, 2024 · 9 comments

Comments

@OdedHorowits
Copy link

Hi

I took the movement functions that the teleopt module uses, i.e. speed.py.
With that speed module I can give the drone an order to go to a direction using velocity vector, and it keeps moving until I tell it to stop.
How do I tell it to stop? two options, both problematic.

  1. I can set the velocity vector to zeros. It stops, after a drift caused by its movement. But it stops.
  2. I can call the 'hover()' function. That stops the drone immediately which is what I need.

But if I use the second option, when performing another movement on another direction, I still get leftovers from the former movement.
For example, if I go 'forwards' (1,0,0), then call hover, and then go 'right' (0,1,0), the drone would go forwards, stops, then go forwards again for half a second and only then fixes its movement and go right.
That is not desirable at all...

Is that a bug?

@pariaspe
Copy link
Member

pariaspe commented Jul 8, 2024

It looks like a bug, @RPS98 any idea on what might be happening?

@OdedHorowits
Copy link
Author

If you want I can add code and screen recording

@pariaspe
Copy link
Member

pariaspe commented Jul 9, 2024

If you want I can add code and screen recording

Sure, that will be helpful to reproduce the error.

@OdedHorowits
Copy link
Author

OdedHorowits commented Jul 9, 2024

So here is my DroneInterface:

from as2_python_api.drone_interface_base import DroneInterfaceBase # /opt/ros/humble/lib/python3.10/site-packages/as2_python_api/drone_interface_base.py
from as2_python_api.drone_interface_teleop import DroneInterfaceTeleop

class MyDroneInterface(DroneInterfaceBase):

    class Directions:
        FORWARD=[1,0,0]
        BACKWARD=[-1,0,0]
        LEFT=[0,1,0]
        RIGHT=[0,-1,0]
        UP=[0,0,1]
        DOWN=[0,0,-1]
        ZERO=[0,0,0]

    def __init__(self, drone_id: str = "drone0", verbose: bool = False,
                 use_sim_time: bool = True) -> None:
        super().__init__(drone_id=drone_id, verbose=verbose, use_sim_time=use_sim_time)
        self.motion = DroneInterfaceTeleop()
        self.pose_frame_id='earth'
        self.twist_frame_id='earth'

    def hover(self):
        """Hover."""
        self.motion.motion_ref_handler.hover()

    def move_at_speed_in_plane(self, velocities, height, yaw_angle=0.0, verbose=False):
        """Move at speed."""
        if verbose:
            cprint(f'DEBUG::move_at_speed_in_plane()\tvelocities: {velocities}\theight: {height}', 'light_green')
        self.motion.motion_ref_handler.speed_in_a_plane.send_speed_in_a_plane_command_with_yaw_angle(
                        twist=velocities,
                        height=height,
                        twist_frame_id=self.twist_frame_id,
                        pose_frame_id=self.pose_frame_id,
                        yaw_angle=yaw_angle
                        )

Then I have a wrapper for using the interface:

from MyDroneInterface import MyDroneInterface

class bridge_test:
    def __init__(self):
        rclpy.init()
        self.drone_interface = MyDroneInterface("drone0", verbose=False, use_sim_time=True)
        self.directions_dict = {
            'FORWARD': self.drone_interface.Directions.FORWARD,
            'BACKWARD': self.drone_interface.Directions.BACKWARD,
            'LEFT': self.drone_interface.Directions.LEFT,
            'RIGHT': self.drone_interface.Directions.RIGHT,
            'UP': self.drone_interface.Directions.UP,
            'DOWN': self.drone_interface.Directions.DOWN,
            'ZERO': self.drone_interface.Directions.ZERO
        }

    def hover(self):
        self.drone_interface.hover()

    def go_to_direction(self, direction, speed=1.0, duration=None, verbose=False):
        self.drone_interface.move_at_speed_in_plane(
            velocities=[speed*d for d in self.directions_dict[direction]],
            height=self.height,
            verbose=verbose
            )

        if duration is not None:
            time.sleep(duration)
            ## Option A - set velocity vector to zero
            self.drone_interface.move_at_speed_in_plane(
                velocities=self.directions_dict['ZERO'],
                height=self.height
            )
            ## Option B - use hover()
            self.hover()

Results of using hover():

using_hover.mp4

Results of using zero velocity:

using_zero_velocity.mp4

(You can see at the first movement the leftovers of the former video that uses hover...)

@pariaspe
Copy link
Member

pariaspe commented Jul 9, 2024

Not sure what it is happening. Also, why are you inheriting from DroneInterfaceBase instead of inheriting directly from DroneInterfaceTeleop? It might not be the issue here but you are duplicating every ros interface in DroneInterfaceBase class

@OdedHorowits
Copy link
Author

You are completely right.
The reason is that I started to use the DroneInterfaceTeleop module functions only after I build the interface...
Anyway I switched it now to inherit from DroneInterfaceTeleop. Thanks for that.
It seems that the 'hover' phenomena is still exist but much more tolerable, as can been seen.
Still, it is a weird behaviour.

using_hover_02.mp4

@RPS98
Copy link
Contributor

RPS98 commented Jul 12, 2024

Hi @OdedHorowits,

This issue should have been fixed in aerostack2/aerostack2#584. Can you test it?

@OdedHorowits
Copy link
Author

I would change the src code according to the change in that issue, re-compile and report.

@OdedHorowits
Copy link
Author

So I cant check it since I installed the package using the binaries...
I will try to builld it from src

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants