Repository navigation
提交代码并运行 #4500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
提交代码并运行 #4500
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| 首次提交选题为无人车安全导航 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import airsim | ||
| import time | ||
|
|
||
|
|
||
| def main(): | ||
| print("=== 尝试连接 AirSimNH (使用 airsim 1.8.1) ===") | ||
| print("重要:请先确保虚幻引擎中的 AirSimNH 已点击播放(Play)!\n") | ||
|
|
||
| try: | ||
| # 1. 创建客户端(1.8.1版本的唯一正确方式) | ||
| client = airsim.CarClient() | ||
| print("✓ 客户端对象创建成功") | ||
|
|
||
| # 2. 确认连接(这会尝试与仿真器通信) | ||
| client.confirmConnection() | ||
| print("✓ 已连接到AirSim仿真服务器") | ||
|
|
||
| # 3. 启用控制 | ||
| client.enableApiControl(True) | ||
| print("✓ API控制已启用") | ||
|
|
||
| # 4. 获取车辆状态,验证一切正常 | ||
| car_state = client.getCarState() | ||
| print(f"✓ 车辆状态获取成功 - 速度: {car_state.speed} km/h") | ||
|
|
||
| # 5. 【可选】简单控制演示 | ||
| print("\n>>> 连接成功!开始简单控制演示...") | ||
| controls = airsim.CarControls() | ||
| controls.throttle = 0.5 | ||
| client.setCarControls(controls) | ||
| time.sleep(2) | ||
| controls.brake = 1.0 | ||
| controls.throttle = 0.0 | ||
| client.setCarControls(controls) | ||
| time.sleep(1) | ||
| print("演示结束。") | ||
| # 6. 释放控制 | ||
| client.enableApiControl(False) | ||
| print("控制权已释放。") | ||
|
|
||
| except ConnectionRefusedError: | ||
| print("\n✗ 连接被拒绝。") | ||
| print(" 最可能的原因:虚幻引擎中的 AirSimNH 仿真没有启动。") | ||
| print(" 请打开虚幻引擎,加载AirSimNH项目,并点击顶部工具栏的蓝色【播放】(▶)按钮。") | ||
| except Exception as e: | ||
| print(f"\n✗ 连接过程中出错: {e}") | ||
| print(" 其他可能原因:防火墙阻止、端口占用或配置文件错误。") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.idea文件夹需要删除