Skip to content

Instantly share code, notes, and snippets.

@varhub
Last active September 7, 2015 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save varhub/7782462ddf0e20d2f81c to your computer and use it in GitHub Desktop.
Save varhub/7782462ddf0e20d2f81c to your computer and use it in GitHub Desktop.
Hello Drone example for JdeRobot/ArDrone
#
# Copyright (C) 1997-2015 JDE Developers Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
# Authors :
# Victor Arribas <v.arribas.urjc@gmail.com>
#
""" @package hellodrone
Hello Drone base code.
Created only thanks to @almartinflorido's introrob_py
"""
import jderobot, Ice
import threading, time
import traceback
class HelloDrone:
def __init__(self):
self.lock = threading.Lock();
self.iceSetup()
def iceSetup(self):
"""
In this function we will initialize ICE communication.
Please, see Python/Ice hello world for more info:
https://zeroc.com/doc/Ice-3.2b/manual/Hello.4.7.html#56529
"""
ice = None;
try:
ice = Ice.initialize()
rawProxy = ice.stringToProxy("Extra:default -h localhost -p 9701")
self.proxyAdvCommands=jderobot.ArDroneExtraPrx.checkedCast(rawProxy)
self.ice = ice
if not self.proxyAdvCommands:
print "Failled to obtain the proxy"
except:
traceback.print_exc()
exit(1)
def sendCmdAdv(self, fn):
funct = getattr(self.proxyAdvCommands, fn)
if self.proxyAdvCommands:
self.lock.acquire()
funct()
self.lock.release()
if __name__ == "__main__":
""" This minimal example will takeoff drone from ground from a second. """
helloDrone = HelloDrone()
helloDrone.sendCmdAdv("takeoff")
time.sleep(3)
helloDrone.sendCmdAdv("land")
""" Teorical TODO:
clean Ice exit (explicit proxy shutdown)
https://zeroc.com/doc/Ice-3.3.0/reference/Ice/Communicator.html#shutdown
"""
if helloDrone.ice:
print "Shutting down Ice communications...."
helloDrone.ice.shutdown();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment