当前位置: 首页>>代码示例>>Python>>正文


Python Arduino.get_wind方法代码示例

本文整理汇总了Python中arduino.Arduino.get_wind方法的典型用法代码示例。如果您正苦于以下问题:Python Arduino.get_wind方法的具体用法?Python Arduino.get_wind怎么用?Python Arduino.get_wind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在arduino.Arduino的用法示例。


在下文中一共展示了Arduino.get_wind方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Boat

# 需要导入模块: from arduino import Arduino [as 别名]
# 或者: from arduino.Arduino import get_wind [as 别名]
class Boat(object):
    def __init__(self, waypointFile=None):
        """Constructor for the boat object"""
        self.arduino = Arduino()
        self.gps = Gps()
        self.xbee = Xbee()
        self._waypointN = 0
        self._waypointE = 0
        self._waypointNumber = 0
        self._waypointDist = 0
        self._waypointHeading = 0
        self._targetHeading = 0
        self._targetDistance = 0

        self.s = 0
        self.c = 0
        self.r = 250

    def log(self, logfilename='logfile'):
        """
        Log the output of the sensors to stdout, a logfile and down the xbee
        """
        try:
            l = 'time={time}\
 bhead={head}\
 wind={wind}\
 lat={pos.lat}\
 lon={pos.long}\
 nwlat={wpn}\
 nwlon={wpe}\
 nwn={num}\
 spos={sail}\
 rpos={rudder}\
 whead={waypointHeading}\
 distance={waypointDistance}\
 speed={speed}\
 thead={targetHeading}\
 tdist={targetDistance}\
 temp={temp}\n\r'.format(
                    time = int(time.time()),
                    head = self.arduino.get_compass(),
                    wind = self.get_wind_average(),
                    pos = self.gps.position,
                    wpn = self._waypointN,
                    wpe= self._waypointE,
                    num = self._waypointNumber,
                    sail = self.arduino.sailAngle,
                    rudder = self.arduino.rudderAngle,
                    waypointHeading = self._waypointHeading,
                    waypointDistance = self._waypointDist,
                    speed = self.gps.speed,
                    targetHeading = self._targetHeading,
                    targetDistance = self._targetDistance,
                    temp = self.arduino.get_compass(),
                )

            # write to log file
            with open(logfilename, 'a') as f:
                f.write(l)

            # write to xbee
            self.xbee.send(l)
            
           # write to console
            log(l)

        except:
            trace = traceback.format_exc()
            with open('errors', 'a') as f:
                f.write(str(time.time()) + ':\n' + trace + '\n')

    def get_wind_bearing(self):
        """Return the absolute bearing of the wind"""
        wind = Bearing(self.arduino.get_wind())
        bearing = Bearing(self.arduino.get_compass())
        return wind + bearing

    def get_wind_average(self):
        self.s += (sin(math.radians(self.get_wind_bearing())) - self.s) / self.r
        self.c += (cos(math.radians(self.get_wind_bearing())) - self.c) / self.r
        a = int(math.degrees(atan2(self.s, self.c)))
        if a < 0:
            return a + 360
        else:
            return a

    def set_waypoint_northing(self, v):
        self._waypointN = v

    def set_waypoint_easting(self, v):
        self._waypointE = v

    def get_waypoint_number(self):
        return self._waypointNumber

    def set_waypoint_number(self, v):
        self._waypointNumber = v

    def set_waypoint_distance(self, v):
        self._waypointDist = v
#.........这里部分代码省略.........
开发者ID:abersailbot-archive,项目名称:sailbot2013,代码行数:103,代码来源:boat.py


注:本文中的arduino.Arduino.get_wind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。