Skip to content

Commit

Permalink
python: Move common utils to mavros.utils module.
Browse files Browse the repository at this point in the history
Issue #157.
  • Loading branch information
vooon committed Sep 17, 2014
1 parent d1d21b1 commit 99d63f4
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 82 deletions.
13 changes: 1 addition & 12 deletions mavros/scripts/mavcmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,15 @@

from __future__ import print_function

import sys
import argparse
import threading

import rospy
from mavros.utils import *
from mavros.srv import CommandLong, CommandInt, CommandHome, CommandTOL, CommandBool
from sensor_msgs.msg import NavSatFix


def print_if(cond, *args, **kvargs):
if cond:
print(*args, **kvargs)


def fault(*args, **kvargs):
kvargs['file'] = sys.stderr
print(*args, **kvargs)
sys.exit(1)


def _check_ret(args, ret):
if not ret.success:
fault("Request failed. Check mavros logs. ACK:", ret.result)
Expand Down
8 changes: 1 addition & 7 deletions mavros/scripts/mavftp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,12 @@

from __future__ import print_function

import os
import sys
import argparse

import rospy
from mavros.utils import *
from mavros.ftp import *

def fault(*args, **kvargs):
kvargs['file'] = sys.stdout
print(*args, **kvargs)
sys.exit(1)


def check_ret(operation, ret):
if not ret.success:
Expand Down
13 changes: 1 addition & 12 deletions mavros/scripts/mavparam
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

from __future__ import print_function

import sys
import csv
import time
import argparse

import roslib; roslib.load_manifest("mavros")
import rospy
from mavros.utils import *
from mavros.srv import ParamPull, ParamPush, ParamGet, ParamSet


Expand Down Expand Up @@ -127,17 +127,6 @@ class QGroundControlParam(ParamFile):
writer.writerow((sysid, compid, p.param_id, p.param_value, to_type(p.param_value), )) # XXX


def print_if(cond, *args, **kvargs):
if cond:
print(*args, **kvargs)


def fault(*args, **kvargs):
kvargs['file'] = sys.stdout
print(*args, **kvargs)
sys.exit(1)


def get_param_file_io(args):
if args.mission_planner:
print_if(args.verbose, "MissionPlanner format")
Expand Down
13 changes: 1 addition & 12 deletions mavros/scripts/mavsafety
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,14 @@

from __future__ import print_function

import sys
import argparse

import rospy
from mavros.utils import *
from geometry_msgs.msg import PolygonStamped, Point32
from mavros.srv import CommandBool


def print_if(cond, *args, **kvargs):
if cond:
print(*args, **kvargs)


def fault(*args, **kvargs):
kvargs['file'] = sys.stderr
print(*args, **kvargs)
sys.exit(1)


def _arm(args, state):
try:
arming_cl = rospy.ServiceProxy(args.mavros_ns + "/cmd/arming", CommandBool)
Expand Down
13 changes: 1 addition & 12 deletions mavros/scripts/mavsetp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

from __future__ import print_function

import sys
import argparse
import math

import rospy
from mavros.utils import *
from std_msgs.msg import Header
from geometry_msgs.msg import TwistStamped, PoseStamped, Vector3, Vector3Stamped, Point, Quaternion
from tf.transformations import quaternion_from_euler
Expand All @@ -32,17 +32,6 @@ from mavros.srv import CommandBool
_ONCE_DELAY = 3


def print_if(cond, *args, **kvargs):
if cond:
print(*args, **kvargs)


def fault(*args, **kvargs):
kvargs['file'] = sys.stderr
print(*args, **kvargs)
sys.exit(1)


def publish_once(args, pub, msg):
pub.publish(msg)
rospy.sleep(0.2)
Expand Down
14 changes: 1 addition & 13 deletions mavros/scripts/mavsys
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,15 @@

from __future__ import print_function

import sys
import argparse
import threading

import rospy
from mavros.utils import *
from mavros.msg import State
from mavros.srv import SetMode, StreamRate, StreamRateRequest


def print_if(cond, *args, **kvargs):
if cond:
print(*args, **kvargs)


def fault(*args, **kvargs):
kvargs['file'] = sys.stderr
print(*args, **kvargs)
sys.exit(1)



def do_mode(args):
rospy.init_node("mavsys", anonymous=True)

Expand Down
15 changes: 1 addition & 14 deletions mavros/scripts/mavwp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

from __future__ import print_function

import sys
import csv
import time
import argparse
import threading

import roslib; roslib.load_manifest("mavros")
import rospy
from mavros.utils import *
from mavros.msg import Waypoint, WaypointList
from mavros.srv import WaypointPull, WaypointPush, WaypointClear, \
WaypointSetCurrent, WaypointGOTO
Expand Down Expand Up @@ -142,22 +142,10 @@ class QGroundControlWP(WaypointFile):
))



def print_if(cond, *args, **kvargs):
if cond:
print(*args, **kvargs)


def get_wp_file_io(args):
return QGroundControlWP()


def fault(*args, **kvargs):
kvargs['file'] = sys.stderr
print(*args, **kvargs)
sys.exit(1)


def _pull(args):
try:
pull_cl = rospy.ServiceProxy(args.mavros_ns + "/mission/pull", WaypointPull)
Expand Down Expand Up @@ -399,4 +387,3 @@ def main():

if __name__ == '__main__':
main()

34 changes: 34 additions & 0 deletions mavros/src/mavros/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- python -*-
# vim:set ts=4 sw=4 et:
#
# Copyright 2014 Vladimir Ermakov.
#
# 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, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

from __future__ import print_function

import os
import sys


def print_if(cond, *args, **kvargs):
if cond:
print(*args, **kvargs)


def fault(*args, **kvargs):
kvargs['file'] = sys.stderr
print(*args, **kvargs)
sys.exit(1)

0 comments on commit 99d63f4

Please sign in to comment.