DJIRonin_Control.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import rospy
00003 from dji_ronin.msg import gimbalangle
00004 import serial
00005 from dji_ronin.srv import controlgimbal_srv
00006 import time
00007 
00008 __author__ = 'Itamar Eliakim'
00009 
00010 class DJIRoninControl():
00011     def __init__(self):
00012         rospy.init_node("DJI_Ronin_Control")
00013         self.port = rospy.get_param("~gimbal_COM","/dev/serial/by-id/usb-Arduino_Srl_Arduino_Uno_85439303033351E051D0-if00")
00014         self.ser = serial.Serial(self.port, 9600)
00015         rospy.sleep(2)
00016         self.time = 0
00017         self.pan = 0
00018         self.tilt = 0
00019         self.roll = 0
00020         self.tolerance = 5
00021         rospy.Subscriber('/GimbalAngle', gimbalangle, self.Handle_Gimbal)
00022         self.s = rospy.Service('/DJI_RotateTo', controlgimbal_srv, self.Rotate_To)
00023         rospy.loginfo("Starting DJI Ronin Control Server")
00024         self.Boot(20)
00025         rospy.spin()
00026 
00027     def Handle_Gimbal(self,data):
00028         self.time = data.header.stamp
00029         self.pan = data.pan
00030         self.tilt = data.tilt
00031         self.roll = data.roll
00032 
00033     def Rotate_To(self,msg):
00034         ## Such a slow system, PID Controller won't give us better results.
00035         if msg.dir==1:
00036             toAngle = (-1)*msg.angle
00037         if msg.dir==2:
00038             toAngle = (1)*msg.angle
00039         for j in range(0,10):
00040             while abs((toAngle) - (self.pan)) > self.tolerance:          ##Error Calc or timeout
00041                 #print abs(toAngle - self.pan)
00042                 if toAngle>self.pan:
00043                     speed = -7                                           ##Values are set by the calibration process
00044                 else:
00045                     speed = 15                                           ##Values are set by the calibration process
00046 
00047                 #print speed
00048                 self.ser.write(str(speed) +"\n\r")
00049             rospy.sleep(0.5)
00050         rospy.loginfo("Done Rotating")
00051         return True
00052 
00053     def Boot(self,speed):
00054         for i in range(0,8):
00055             self.ser.write(str(speed) + "\n\r")
00056             time.sleep(0.5)
00057 
00058 if __name__ == "__main__":
00059     DJIRoninControl()


dji_ronin
Author(s):
autogenerated on Sat Jun 8 2019 20:15:31