RiCOpenDiff.py
Go to the documentation of this file.
00001 from threading import Thread
00002 from BAL.Header.Response.ParamBuildResponse import DiffDriverOL
00003 
00004 __author__ = 'tom1231'
00005 from BAL.Interfaces.Device import Device
00006 from rospy import Subscriber
00007 from geometry_msgs.msg import Twist
00008 from std_msgs.msg import Float32
00009 
00010     # _right->setStartPoint(((v / _rWheel) + (_weigh * w / (2 * _rWheel))));
00011     # _left->setStartPoint(((v / _rWheel) - (_weigh * w / (2 * _rWheel))));
00012     # openLoopCallback
00013 
00014 class RiCOpenDiff(Device):
00015 
00016     def __init__(self, param, motorL, motorR):
00017         Device.__init__(self, param.getCloseDiffName(), None)
00018         self._maxAng = param.getCloseDiffMaxAng()
00019         self._rWheel = param.getCloseDiffRWheel()
00020         self._width = param.getCloseDiffWidth()
00021         self._maxLin = param.getCloseDiffMaxLin()
00022         self._motorL = motorL
00023         self._motorR = motorR
00024         Subscriber('%s/command' % self._name, Twist, self.diffCallback)
00025 
00026     def sendMsg(self, msg):
00027         if msg.angular.z > self._maxAng:
00028             msg.angular.z = self._maxAng
00029         elif msg.angular.z < -self._maxAng:
00030             msg.angular.z = -self._maxAng
00031         if msg.linear.x > self._maxLin:
00032             msg.linear.x = self._maxLin
00033         elif msg.linear.x < -self._maxLin:
00034             msg.linear.x = -self._maxLin
00035 
00036         msgR = Float32()
00037         msgL = Float32()
00038         w_max = self._maxLin / self._rWheel
00039 
00040         resR = ((msg.linear.x / self._rWheel) + (self._width * msg.angular.z / (2 * self._rWheel)))
00041         resL = ((msg.linear.x / self._rWheel) - (self._width * msg.angular.z / (2 * self._rWheel)))
00042 
00043         msgR.data = resR / w_max
00044         self._motorR.openLoopCallback(msgR)
00045 
00046         msgL.data = resL / w_max
00047         self._motorL.openLoopCallback(msgL)
00048 
00049     def diffCallback(self, msg):
00050         Thread(target=self.sendMsg, args=(msg,)).start()
00051 
00052     def getType(self): return DiffDriverOL
00053 
00054     def publish(self, data):
00055         pass


ric_board
Author(s): RoboTiCan
autogenerated on Fri Oct 27 2017 03:02:31