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

Not Working for JJRC H37 #4

Open
praveeno opened this issue Dec 7, 2019 · 5 comments
Open

Not Working for JJRC H37 #4

praveeno opened this issue Dec 7, 2019 · 5 comments

Comments

@praveeno
Copy link

praveeno commented Dec 7, 2019

@3demax I tried to run kbd_flight.py with default spin_up command, but its not working

@3demax
Copy link
Owner

3demax commented Dec 8, 2019

Did you connect any joystick? Without one, it wouldn't work now.
I've updated the code do show you the name of the joystick connected (is any), in this commit:

@praveeno
Copy link
Author

praveeno commented Dec 9, 2019

hey @3demax ,
actually i comment all joystick releated code, so i can control it programatically
and use cmd = 'spin_up' by default in main_loop,
so a/c code flow, it should work

@praveeno
Copy link
Author

@3demax hey did you got time ?

@3demax
Copy link
Owner

3demax commented Feb 24, 2020

Hi @praveeno, I don't want to develop this project anymore. It was fun and I hope someone will find it helpful, but I will not actively developing one.
Despite that, feel free to submit PRs! I'll do my best to provide suggestion if needed.

To recap, this is my last reply on how you can use the code to control the drone programmatically:
If you are looking for an API to control the drone from code, the module you are looking for is drone.py. All that is really needed is to send the command string on some interval, like how it's done in kbd_flight.py:

drone_command = drone.get_command_string(
    roll=roll, pitch=pitch, throttle=throttle, yaw=yaw, command=cmd,
    altitude_hold=True
)  # assembles encoded command string
drone1.execute(drone_command)  # sends encoded string over UDP to the drone

Your job is to send the encoded string to the drone frequently (in my tests, 60Hz is enough, 120Hz is slightly better). Note that you need to send a command sequence even if your inputs doesn't change (if you have no command to the drone). Otherwise the drone may think the connection is lost and will initiate automatic soft landing.

If I would need to implement this, I would have something like a list of instruction to the drone and a loop with the timer:

FREQ = 1.0/60.0  # theoretically, the lower it is, the more responsive drone is. test and adjust if needed
instructions = [
    (0, 0, 0, 0, 'spin_up'),  # turn motors on 
    (0, 0, 0.5, 0, None),     # go up
]

for instruction in instructions:
    drone1.execute(drone.get_command_string(*instruction, altitude_hold=True))
    time.sleep(FREQ)

# send command during the idle time to keep the drone under control
condition = True
while condition:
    drone1.execute(drone.get_command_string(0, 0, 0, 0, None, altitude_hold=True))
    time.sleep(FREQ)

You would probably need to add durations for instructions to make it work, but it shouldn't be hard if you are familiar with python.

@praveeno
Copy link
Author

Thanks @3demax, I'll update you on process status

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

2 participants