import requests import os import pickle from Queue import Queue import config from utils.logger2 import getLogger logger = getLogger('utils.inspection_status') logger.propagate = False Robot_Task_Cache = Queue() Robot_Task_Cache_File = '/robot_task_cache.pkl' class File(object): def __init__(self, file_path): if not os.path.exists(file_path): raise OSError('{file_path} not exist'.format(file_path=file_path)) self.file_path = os.path.abspath(file_path) def status(self): open_fd_list = self.__get_all_fd() open_count = len(open_fd_list) is_opened = False if open_count > 0: is_opened = True return {'is_opened': is_opened, 'open_count': open_count} def __get_all_pid(self):
import copy import datetime from influxdb import InfluxDBClient import config from utils.logger2 import getLogger logger = getLogger('utils-tsdb') body_pos = { 'measurement': config.Table_Name_Robot_Pos, 'time': 0, 'tags': { 'robot_id': 0, 'inspection_id': 0, }, 'fields': { 'pos_x': 0, 'pos_y': 0, 'pos_angle': 0 } } body_event = { 'measurement': config.Table_Name_Robot_Event, 'time': 0, 'tags': { 'robot_id': 0, 'inspection_id': 0, 'waypoint_no': 0 },
import rospy from geometry_msgs.msg import Twist from utils.logger2 import getLogger logger = getLogger('RotateController') logger.propagate = False PI = 3.1415926535897 class RotateController(): def __init__(self, inspection_id, robot_id): self.inspection_id = inspection_id self.robot_id = robot_id self.msg_head = 'inspection:{} robot: {}: '.format( inspection_id, robot_id) self.rotate_pub = rospy.Publisher('/{}/cmd_vel'.format(self.robot_id), Twist, queue_size=10) self.rotate_command = Twist() rospy.on_shutdown(self.shutdown) def rotate(self, angle=90, speed=90, clockwise=True, stay=2): #Converting from angles to radians angular_speed = 1.0 #speed*PI/180 relative_angle = angle * PI / 180 #We wont use linear components self.rotate_command.linear.x = 0
from tf.transformations import euler_from_quaternion from geometry_msgs.msg import Point, Twist, Pose from apscheduler.schedulers.background import BackgroundScheduler import yaml import config from turtlebot_goto import GoToPose from turtlebot_rotate import RotateController, PI from turtlebot_initpose import PoseIniter from tsdb import DBHelper from nav_math import distance, radiou2dgree from turtlebot_robot_status import setRobotIdel, setRobotWorking, isRobotWorking from utils.logger2 import getLogger from utils.turtlebot import checkRobotNode, shell_cmd, killNavProcess logger = getLogger('turtlebot_cruise') logger.propagate = False def initParas(): dababody = { 'inspection_id': 0, 'robot_id': 0, 'original_pose': None, 'cur_x': 0, 'cur_y': 0, 'cur_theta': 0, 'cur_time': 0, 'pre_time': 0, 'robot_status': { 'id': 0,
#!/usr/bin/env python import os import re import time import requests from wand.image import Image import config from utils.turtlebot import shell_cmd from utils.logger2 import getLogger logger = getLogger('map_utils') logger.propagate = False def saveMap(map_path): if not os.path.exists(map_path): os.makedirs(map_path) #export map from ros map_server mapfilepath = os.path.join(map_path, 'map') cmd = 'rosrun map_server map_saver -f {}'.format(mapfilepath) result, _ = shell_cmd(cmd) if result == 1: logger.error('saveMap: error in running ' + cmd) return None logger.info( 'saveMap: succeeded in export site map to path: {}'.format(map_path))
from django.shortcuts import render from rest_framework.decorators import api_view from rest_framework.decorators import parser_classes from rest_framework import status from rest_framework.response import Response #from rest_framework.decorators import JSONParser from nav_utils.turtlebot_launch import Turtlebot_Launcher from nav_utils.turltlebot_cruise import runRoute from nav_utils.turtlebot_robot_status import setRobotWorking, setRobotIdel, isRobotWorking from config import Nav_Pickle_File, Inspection_Status_Codes, Task_Type, Robot_Model from utils.turtlebot import killNavProcess, initROSNode, checkMapFile from utils.msg_center import addTaskIntoMsgQueue, getTasksFromMsgQueue from utils.logger2 import getLogger logger = getLogger('launch_av endpoint') logger.propagate = False @api_view(['POST']) #@parser_classes([parser_classes.JSONParser]) def index(request): """ the post data should be in json and like: { 'inspection_id': 103, 'site_id': 'office12' 'robots': { 'robot_id1': { 'org_pos': "(1.4, 10.5, 0)", 'subtask': "[(1, x1, y1), (2, x2, y2), ...]"
#!/usr/bin/env python import sys import os import getopt from map_utils import deleteRemoteSite, createRemoteSite, saveMap import config from utils.turtlebot import checkRobotNode from utils.logger2 import getLogger logger = getLogger('createSite') logger.propagate = False def createSite(sitename='test', description='', forced=True): if not checkRobotNode('map_server', trytimes=1): logger.error('createsite exit! Not found map_server') raise Exception('not found map_server from rosnode') map_path = os.path.join(config.Map_Dir, sitename) if os.path.exists(map_path): if not forced: logger.info( 'site {} existed! choose not to overwrite existed site!'. format(sitename)) try: deleteRemoteSite(sitename) saveMap(map_path) createRemoteSite(sitename, description)
import copy import time import pickle import xml.etree.ElementTree as ET from os.path import expanduser import rospy import tf from config import ROS_Launch_File, Map_Dir, Launch_Max_Try, Nav_Pickle_File, DEBUG from utils.turtlebot import checkRobotNode, shell_open #from utils.logger import logger from utils.logger2 import getLogger logger = getLogger('Turtlebot_Launcher') logger.propagate = False class Turtlebot_Launcher(): def __init__(self, siteid, robots): self.robots = robots self.siteid = siteid def launch(self): launched = False for i in range(Launch_Max_Try): logger.info( 'Start trial no. {} to launch navigation in multirobot mode!'. format(i + 1))
import requests import json from config import Msg_Center_Endpoint from utils.logger2 import getLogger logger = getLogger('utils.msg_center') logger.propagate = False def addTaskIntoMsgQueue(data, tasktype=-1): is_error = False try: response = requests.post(Msg_Center_Endpoint, data={tasktype: json.dumps(data)}) if response.status_code != 200: is_error = True except Exception as e: logger.error(str(e)) is_error = True if is_error: msg = "Failed to upload task data to MSG center! " logger.error(msg) raise Exception(msg) logger.info("Succeeded to upload task data to MSG center!") def getTasksFromMsgQueue():
#!/usr/bin/env python import os import sys #from utils.turtlebot import killNavProcess from utils.logger2 import getLogger logger = getLogger('manage.py') logger.propagate = False if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "robotmaster.settings") #kill existed navigation process # logger.info('try to kill existed navigation process!') # killNavProcess() try: from django.core.management import execute_from_command_line except ImportError: # The above import may fail for some other reason. Ensure that the # issue is really that Django is missing to avoid masking other # exceptions on Python 2. try: import django except ImportError: raise ImportError( "Couldn't import Django. Are you sure it's installed and " "available on your PYTHONPATH environment variable? Did you " "forget to activate a virtual environment?" )
# -*- coding: utf-8 -*- from __future__ import unicode_literals from rest_framework.decorators import api_view from rest_framework.decorators import parser_classes from rest_framework import status from rest_framework.response import Response #from rest_framework.decorators import JSONParser from msg_utils import putTask, getTask from utils.logger2 import getLogger logger = getLogger('msg_center endpoint') logger.propagate = False @api_view(['POST', 'GET']) #@parser_classes([parser_classes.JSONParser]) def index(request): if request.method == 'POST': putTask(request.data) logger.info("new task added into MSG queue!") return Response("new task added into MSG queue!", status=status.HTTP_200_OK) else: task_data = getTask() logger.info("get new task: {} from MSG queue!".format(task_data)) return Response(data=task_data, status=status.HTTP_200_OK)
# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.shortcuts import render from rest_framework.decorators import api_view from rest_framework import status from rest_framework.response import Response from createsite import createSite #from utils.logger import logger from utils.logger2 import getLogger logger = getLogger('createsite endpoint') logger.propagate = False @api_view(['GET']) def index(request): # print(request.query_params) if 'name' not in request.query_params.keys(): return Response(('name required'), status=status.HTTP_400_BAD_REQUEST) else: name = request.query_params['name'] desc = '' if 'desc' in request.query_params.keys(): desc = request.query_params['desc'] forced = True if 'forced' in request.query_params.keys(): if request.query_params['forced'].lower() not in ['y', 'yes', 'true']: forced = False
import rospy import actionlib from actionlib_msgs.msg import * from geometry_msgs.msg import Pose, PoseWithCovarianceStamped from tf.transformations import euler_from_quaternion, quaternion_from_euler import math from random import sample from config import Trial_Set_Pose_Count from utils.logger2 import getLogger logger = getLogger('turtlebot_initpose') logger.propagate = False class PoseIniter(): def __init__(self, inspection_id, robot_id, init_x, init_y, init_a): self.inspection_id = inspection_id self.robot_id = robot_id self.msg_head = 'inspection:{} robot: {}: '.format( inspection_id, robot_id) # self.setpose_pub = rospy.Publisher('/{}/initialpose'.format(self.robot_id), PoseWithCovarianceStamped, latch=True, queue_size=1) self.setpose_pub = rospy.Publisher('/{}/initialpose'.format( self.robot_id), PoseWithCovarianceStamped, queue_size=10) self.trial_set_pose_flag = True self.init_pose = {'x': init_x, 'y': init_y, 'a': init_a} rospy.sleep(1) rospy.on_shutdown(self.shutdown)
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ''' # TurtleBot must have minimal.launch & amcl_demo.launch # running prior to starting this script # For simulation: launch gazebo world & amcl_demo prior to run this script import rospy from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal import actionlib from actionlib_msgs.msg import * from geometry_msgs.msg import Pose, Point, Quaternion from config import Wait_For_GoToPose_Time, DEBUG from utils.logger2 import getLogger logger = getLogger('GoToPose') class GoToPose(): def __init__(self, inspection_id, robot_id): self.inspection_id = inspection_id self.robot_id = robot_id self.msg_head = 'inspection:{} robot: {}: '.format( inspection_id, robot_id) self.goal_sent = False # What to do if shut down (e.g. Ctrl-C or failure) rospy.on_shutdown(self.shutdown)