Example #1
0
    def __init__(self):
        self.vel_control = rospy.Publisher('/position_control/set_velocity',
                                           PoseStamped,
                                           queue_size=10)
        rospy.Subscriber('/position_control/distance', Bool,
                         self.distance_reached_cb)
        self.mode_control = rospy.Publisher('/position_control/set_mode',
                                            String,
                                            queue_size=10)
        print('Setting offboard')
        mv_state = mavros_state.mavros_state()
        mv_state.set_mode('OFFBOARD')
        print('Arming vehicle')
        mv_state.arm(True)
        rospy.loginfo("Taking off")
        self.goto_position_client = actionlib.SimpleActionClient(
            'goto_position', goto_positionAction)
        # Will return True or False
        self.goto_position_client.wait_for_server()
        self.goto_position_goal = goto_positionGoal()
        self.goto_position_goal.destination.pose.position.z = 3
        self.goto_position_client.send_goal(self.goto_position_goal)
        self.goto_position_client.wait_for_result()

        self.des_pose = PoseStamped()

        self.mode_control.publish('velctr')
        rospy.sleep(0.1)

        # Fly back and forth
        print(str(PoseStamped))
        self.des_pose.pose.position.x = 0
        self.des_pose.pose.position.y = 1
        self.des_pose.pose.position.z = 3
        self.vel_control.publish(self.des_pose)
        # while not self.target_reached:
        rospy.sleep(20)

        while True:
            print(str(PoseStamped))
            self.des_pose.pose.position.x = 0
            self.des_pose.pose.position.y = -2
            self.des_pose.pose.position.z = 3
            self.vel_control.publish(self.des_pose)
            # while not self.target_reached:
            rospy.sleep(20)

            print('IN WHILE222')
            self.des_pose.pose.position.x = 0
            self.des_pose.pose.position.y = 2
            self.des_pose.pose.position.z = 3
            self.vel_control.publish(self.des_pose)
            # while not self.target_reached:
            rospy.sleep(20)
            print('IN WHILE333')
    def start_position_server(cls):
        cls.mv_state = mavros_state.mavros_state()
        # cls.mv_state = mavros_state.mavros_state()
        if cls.mv_state is None:
            print("!!!!!!!!!!!!!!!!!!!!!!MV_STATE DID NOT GET SET!!!!!!!!!!!!!!!!!!!!!!")
        else:
            print("MV_STATE got set!! :) ")
        cls.mv_state.set_mode('OFFBOARD')
        # rospy.loginfo('Arming vehicle')
        cls.mv_state.arm(True)

        rospy.Subscriber('/mavros/local_position/pose', PoseStamped, cls._local_pose_callback)

        cls.goto_position_client = actionlib.SimpleActionClient('goto_position', goto_positionAction)
        cls.goto_position_client.wait_for_server()
Example #3
0
import rospy
import actionlib
import mavros_state
import time

from autonomous_offboard.msg import center_on_objectAction,  center_on_objectGoal, descend_on_objectAction, descend_on_objectGoal, detect_objectAction, detect_objectGoal, goto_positionAction, goto_positionGoal, short_grippersAction, short_grippersGoal, long_grippersAction, long_grippersGoal, coverageAction, coverageGoal

from std_msgs.msg import Float32
from geometry_msgs.msg import PoseStamped

if __name__ == '__main__':
    rospy.init_node('action_controller_test')
    goto_position_client = actionlib.SimpleActionClient('goto_position', goto_positionAction)
    goto_position_client.wait_for_server()
    goto_position_goal = goto_positionGoal()
    mv_state = mavros_state.mavros_state()
    print 'Setting offboard'
    mv_state.set_mode('OFFBOARD')
    print 'Arming vehicle'
    mv_state.arm(True)
    rospy.loginfo("Taking off")
    time.sleep(10)

    rospy.loginfo("First position")
    goto_position_goal.destination.pose.position.x = 20
    goto_position_goal.destination.pose.position.y = 0
    goto_position_goal.destination.pose.position.z = 3
    goto_position_client.send_goal(goto_position_goal)
    goto_position_client.wait_for_result()

    time.sleep(10)