×

无人机应用程序:辐射检测

消耗积分:0 | 格式:zip | 大小:0.00 MB | 2023-06-14

卞轮辉

分享资料个

描述

这是 Dronesmith Technologies 的 Dronesmith API 的示例项目。Dronesmith API 是一个基于 HTTP 请求的 API,支持软件优先无人机开发。您可以在 API 中内置的虚拟无人机上测试您的代码,然后在真实无人机上部署相同的代码。该项目使用虚拟无人机在虚构的场景中完成任务。

这个项目需要一些 Python 和 HTML/CSS 的基本经验。

在开始之前,我们建议您查看我们的Dronesmith API 教程。

情景

苏黎世大学一位精神错乱的物理学教授一直在校园北侧的各种建筑物中进行实验。昨晚,他用放射性材料进行的一项实验出现了严重错误,校园变得充满了放射性。现在由您和您的团队使用配备辐射传感器的无人机找到失败实验的位置。

任务

构建一个应用程序,让无人机在校园周围飞行,同时测量辐射强度水平并识别包含辐射源的建筑物。

提示:辐射强度遵循牛顿反平方定律。

 
pYYBAGNY2kOANeo7AAH1EtD9ICM085.png
 

关于 API

在我们深入了解应用程序的工作原理之前,让我们先回顾一下 Dronesmith API。无人机的命令采用 HTTP 请求的形式。例如,要检索无人机的位置,您可以向 URL http://api.dronesmith.io/api/drone/{drone-name}/position发送请求下面是一个使用 Python 模块请求的 API 调用示例。

import json  
import requests
USER_EMAIL      = 'example@example.com'  
USER_API_KEY    = 'example-api-key'  
DRONE_NAME      = 'prickly_galileo' 
  
headers = { 
   'user-email': USER_EMAIL, 
   'user-key': USER_API_KEY,      
   'Content-Type': 'application/json' 
}   
response = requests.get('http://api.dronesmith.io/api/drone/'+ DRONE_NAME + '/position', headers=headers)   
jsonText = json.loads(response.text)  
print json.dumps(jsonText, indent=2, sort_keys=True)  

此代码发送一个 GET 请求并打印来自服务器的响应。服务器使用以下 JSON 对象进行响应。

{ 
   "X": 0.004026684,    
   "Y": -0.02161496,   
   "Z": -0.11607925,   
   "Latitude": 47.39774,   
   "Longitude": 8.545593,   
   "Altitude": 0.047, 
   "Heading": 3.95 
} 

一些请求具有 BODY 字段,例如以下起飞命令。

import json  
import requests 
USER_EMAIL      = 'example@example.com'  
USER_API_KEY    = 'example-api-key'  
DRONE_NAME      = 'prickly_galileo'
  
headers = { 
   'user-email': USER_EMAIL, 
   'user-key': USER_API_KEY,      
   'Content-Type': 'application/json' 
}   
# Command drone to takeoff and hover 20 meters above Lat: 47.399091, Lon: 8.549200  
response = requests.post('http://api.dronesmith.io/api/drone/' + DRONE_NAME + '/takeoff', json={          
   "lat": 47.399091,      
   "lon": 8.549200,     
   "altitude": 20 
}, headers=headers)   
jsonText = json.loads(response.text)  
print json.dumps(jsonText, indent=2, sort_keys=True)  

对此起飞请求的响应是以下确认。

{  
   "Command": 22,  
   "Status": "Command accepted.",  
   "StatusCode": 0  
}  

有关更多示例,请参阅我们的API 参考

对于单个 API 请求,使用 Python 或任何脚本语言可能有点麻烦。我们强烈推荐使用Postman API 工具来测试 Dronesmith API 请求。

先决条件

要完成此项目,您需要 Dronesmith API 密钥。前往api.dronesmith.io请求 API 密钥。几分钟后,您将收到一封包含您的密钥的电子邮件。

您还需要一个 Google Developers API 密钥。https://developers.google.com/maps/documentation/javascript/get-api-key

设置 Python

安装 Python:https ://www.python.org/downloads/release/python-2712/

注意:确保您使用的是 Python 2.7,而不是 Python 3。在命令行中键入 python --version 以验证您的版本。

如果您不熟悉使用 Python,请通过以下两个入门练习来设置您的开发人员环境:

http://learnpythonthehardway.org/book/ex0.html

http://learnpythonthehardway.org/book/ex1.html

安装 Python pip 模块:https ://pip.pypa.io/en/stable/installing/

这应该默认包含在最新的 Python 版本中。

安装 Python 请求模块:pip install requests

安装 Python geopy 模块:pip install geopy

如果你在 Windows 上,你可能需要运行python -m pip 而不只是 pip。

应用程序

您可以从我们的 Github 下载示例应用程序。

https://github.com/dronesmith/Radiation-Detection-Example

该应用程序命令虚拟无人机在苏黎世大学校园周围的路径上飞行,同时在地图上绘制路径。它还显示沿飞行路径的每个点的辐射强度值。

当前形式的应用程序将找不到辐射源。您可以根据自己的策略来修改应用程序以查找带有辐射源的建筑物。

该应用程序由4个文件组成

  • 索引.html
  • 服务器.py
  • 辐射传感器.py
  • 用户帐户.json
 
poYBAGNY2kaAEJX-AABd_OJIfBE214.png
 

这些文件的主要工作是server.py 在此文件中,启动了一个通过端口 8080 在 localhost 上运行的 Web 服务器。它提供无人机的当前位置和传感器数据。

Web 服务器通过发送 Dronesmith API 请求定期检索无人机的位置和无人机辐射传感器的强度值。在与网络服务器不同的线程中,通过发出 Dronesmith API 请求,指示无人机在校园周围的脚本路径中飞行。

index.html中,通过向 http//:localhost:8080/data 发送 GET 请求来定期检索位置和强度值。在每个 GET 请求之后,无人机标记和飞行路径都会更新,并使用 Google Maps API 在最新位置绘制一个半径与辐射强度成正比的新圆圈。

文件radiation_sensor.py用作我们的模拟辐射传感器。该文件定期获取无人机位置并使用纬度和经度值计算辐射强度值。然后它会更新无人机辐射传感器的强度场值。在运行server.py文件之前,您需要在单独的终端中运行此代码。

JSON 文件user-account.json用于存储 Dronesmith API 凭据。

Github 项目中还包含一个设置脚本,drone_setup.py,您可以运行该脚本以在您的帐户上创建具有辐射传感器对象的虚拟无人机。

运行应用程序

按照以下步骤运行应用程序并查看它的运行情况。

1. 下载或克隆 Github 项目。

https://github.com/dronesmith/Radiation-Detection-Example

2. 将您的电子邮件和 Dronesmith API 密钥添加到user.json。

将drone_name 字段留空。

3. 将您的 Google Developers API 密钥添加到index.html

在 HTML 正文中找到包含map.googleapis.com源的脚本,并将您的密钥添加到 URL 中的密钥字段。


4. 运行python drone_setup.py

这将在您的帐户上创建一个新的虚拟无人机并为其添加一个辐射传感器。

5. 运行并让它继续运行。python radiation_sensor.py

6.在另一个终端运行python server.py

7. 访问http://localhost:8080

您应该会立即看到 Google 地图视图。无人机标记将在页面加载后大约 10 秒内显示。直到无人机起飞并达到所需高度后,标记才会移动。然后你应该看到无人机在校园里绕了一圈。

 

寻找辐射源

您可以采取许多不同的策略来定位辐射源。您可能对来源的位置有预感并更改无人机路径以测试您的假设,或者您可能使用花哨的三角测量算法。重要的是你在为时已晚之前找到辐射源。

注意:当您准备好检查您的解决方案时,可以在Radiation_sensor.py文件中找到实际的源纬度和经度。

请告诉我们您寻找辐射源的方法。

祝无人机工匠们好运!

有用的网址


声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !

'+ '

'+ '

'+ ''+ '
'+ ''+ ''+ '
'+ ''+ '' ); $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code ==5){ $(pop_this).attr('href',"/login/index.html"); return false } if(data.code == 2){ //跳转到VIP升级页面 window.location.href="//m.obk20.com/vip/index?aid=" + webid return false } //是会员 if (data.code > 0) { $('body').append(htmlSetNormalDownload); var getWidth=$("#poplayer").width(); $("#poplayer").css("margin-left","-"+getWidth/2+"px"); $('#tips').html(data.msg) $('.download_confirm').click(function(){ $('#dialog').remove(); }) } else { var down_url = $('#vipdownload').attr('data-url'); isBindAnalysisForm(pop_this, down_url, 1) } }); }); //是否开通VIP $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code == 2 || data.code ==5){ //跳转到VIP升级页面 $('#vipdownload>span').text("开通VIP 免费下载") return false }else{ // 待续费 if(data.code == 3) { vipExpiredInfo.ifVipExpired = true vipExpiredInfo.vipExpiredDate = data.data.endoftime } $('#vipdownload .icon-vip-tips').remove() $('#vipdownload>span').text("VIP免积分下载") } }); }).on("click",".download_cancel",function(){ $('#dialog').remove(); }) var setWeixinShare={};//定义默认的微信分享信息,页面如果要自定义分享,直接更改此变量即可 if(window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == 'micromessenger'){ var d={ title:'无人机应用程序:辐射检测',//标题 desc:$('[name=description]').attr("content"), //描述 imgUrl:'https://'+location.host+'/static/images/ele-logo.png',// 分享图标,默认是logo link:'',//链接 type:'',// 分享类型,music、video或link,不填默认为link dataUrl:'',//如果type是music或video,则要提供数据链接,默认为空 success:'', // 用户确认分享后执行的回调函数 cancel:''// 用户取消分享后执行的回调函数 } setWeixinShare=$.extend(d,setWeixinShare); $.ajax({ url:"//www.obk20.com/app/wechat/index.php?s=Home/ShareConfig/index", data:"share_url="+encodeURIComponent(location.href)+"&format=jsonp&domain=m", type:'get', dataType:'jsonp', success:function(res){ if(res.status!="successed"){ return false; } $.getScript('https://res.wx.qq.com/open/js/jweixin-1.0.0.js',function(result,status){ if(status!="success"){ return false; } var getWxCfg=res.data; wx.config({ //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId:getWxCfg.appId, // 必填,公众号的唯一标识 timestamp:getWxCfg.timestamp, // 必填,生成签名的时间戳 nonceStr:getWxCfg.nonceStr, // 必填,生成签名的随机串 signature:getWxCfg.signature,// 必填,签名,见附录1 jsApiList:['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); wx.ready(function(){ //获取“分享到朋友圈”按钮点击状态及自定义分享内容接口 wx.onMenuShareTimeline({ title: setWeixinShare.title, // 分享标题 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享给朋友”按钮点击状态及自定义分享内容接口 wx.onMenuShareAppMessage({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 type: setWeixinShare.type, // 分享类型,music、video或link,不填默认为link dataUrl: setWeixinShare.dataUrl, // 如果type是music或video,则要提供数据链接,默认为空 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ”按钮点击状态及自定义分享内容接口 wx.onMenuShareQQ({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口 wx.onMenuShareWeibo({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ空间”按钮点击状态及自定义分享内容接口 wx.onMenuShareQZone({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); }); }); } }); } function openX_ad(posterid, htmlid, width, height) { if ($(htmlid).length > 0) { var randomnumber = Math.random(); var now_url = encodeURIComponent(window.location.href); var ga = document.createElement('iframe'); ga.src = 'https://www1.elecfans.com/www/delivery/myafr.php?target=_blank&cb=' + randomnumber + '&zoneid=' + posterid+'&prefer='+now_url; ga.width = width; ga.height = height; ga.frameBorder = 0; ga.scrolling = 'no'; var s = $(htmlid).append(ga); } } openX_ad(828, '#berry-300', 300, 250);