当前位置: 首页 > news >正文

ros2机器开发人员必看,如何配置环境让人工智能全程参与开发第一部分,初始化环境

我们在开发机器人的时候,如果全程让人工智能与,我们第一步是环境要给大模型初始化好,避免进程在等待,或因权限原因ai 不能办到换一个方法实现现,无数次
偿试浪费token ,所以我们得在环境上就规范起来,这样才有更好的开发环境,

!/bin/bash

set -e

echo ""
echo " ROS2 Humble 完整安装脚本 (Ubuntu 22.04)"
echo "
"

设置 locale

echo "[1/8] 配置 locale..."
sudo apt update
sudo apt install -y locales
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8

确保 universe 仓库已启用

echo "[2/8] 启用 universe 仓库..."
sudo apt install -y software-properties-common
sudo add-apt-repository universe -y

添加 ROS2 GPG 密钥

echo "[3/8] 添加 ROS2 GPG 密钥..."
sudo apt install -y curl gnupg lsb-release
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

添加 ROS2 源

echo "[4/8] 添加 ROS2 apt 源..."
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

更新包索引

echo "[5/8] 更新 apt 包索引..."
sudo apt update

安装 ROS2 Humble 完整桌面版(desktop-full)

echo "[6/8] 安装 ROS2 Humble Desktop Full(完整安装,这可能需要较长时间)..."
sudo apt install -y ros-humble-desktop-full

安装开发工具

echo "[7/8] 安装 ROS2 开发工具(colcon、rosdep 等)..."
sudo apt install -y ros-dev-tools
sudo apt install -y python3-colcon-common-extensions

初始化 rosdep

echo "[8/8] 初始化 rosdep..."
sudo rosdep init 2>/dev/null || true
rosdep update

配置环境变量到 .bashrc

echo "" >> ~/.bashrc
echo "# ROS2 Humble 环境配置" >> ~/.bashrc
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
echo "export LANG=en_US.UTF-8" >> ~/.bashrc

立即加载环境

source /opt/ros/humble/setup.bash

echo ""
echo ""
echo " ROS2 Humble 安装完成!"
echo "
"
echo ""
echo "已安装内容:"
echo " - ros-humble-desktop-full(完整桌面版)"
echo " - ros-dev-tools(开发工具)"
echo " - python3-colcon-common-extensions(colcon 构建工具)"
echo " - rosdep(依赖管理工具)"
echo ""
echo "环境已自动配置到 ~/.bashrc"
echo "新终端会自动加载 ROS2 环境"
echo ""
echo "验证安装:"
ros2 --version 2>/dev/null || echo "(需要新开终端或执行: source ~/.bashrc)"
echo ""
echo "常用命令:"
echo " ros2 run 运行节点"
echo " ros2 launch 启动 launch 文件"
echo " ros2 topic list 查看话题列表"
echo " colcon build 编译工作空间"

New System Setup Guide

Rule: First configure the development environment, then write code.


Phase 1: Windows PowerShell

1.1 Execution Policy

Set-ExecutionPolicy -Scope CurrentUser RemoteSigned -Force

Why: Default Restricted blocks all scripts. Every command reports profile.ps1 forbidden, wasting tokens on retries.

1.2 UTF-8 Encoding

Create or edit C:\Users\fgxwa\Documents\WindowsPowerShell\profile.ps1:

# UTF-8 encoding config
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8# conda initialize (keep your own conda path)
#region conda initialize
If (Test-Path "D:\ProgramData\anaconda3\Scripts\conda.exe") {(& "D:\ProgramData\anaconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | ?{$_} | Invoke-Expression
}
#endregion

Why: Without UTF-8 config, Chinese output becomes garbled. Profile comments MUST be English only - Chinese comments in profile.ps1 become garbled even with UTF-8 set.

Verify:

# Close and reopen PowerShell, then:
# Should NOT see any "profile.ps1 forbidden" error
# Chinese characters should display correctly

Phase 2: Windows SSH Config

Edit C:\Users\fgxwa\.ssh\config:

Host ubuntu-vmHostName 192.168.241.138User xsyIdentityFile ~/.ssh/id_rsaServerAliveInterval 30ServerAliveCountMax 5TCPKeepAlive yesConnectTimeout 10Host *ServerAliveInterval 30ServerAliveCountMax 5TCPKeepAlive yesStrictHostKeyChecking accept-new

Why - ServerAliveInterval: SSH sends heartbeat every 30 seconds to prevent the connection from being killed by NAT/firewall during long operations (apt install, colcon build, etc.). Without this, SSH hangs silently with no output and no error - looks "frozen".

Why - StrictHostKeyChecking accept-new: After VM reinstall, the host key changes. Without this, SSH refuses to connect and you need to manually ssh-keygen -R each time.

Verify:

ssh ubuntu-vm "echo OK"
# Should connect immediately without password

Phase 3: Ubuntu Remote Server

3.1 SSH Server

sudo apt install -y openssh-server
sudo systemctl enable --now ssh

3.2 Passwordless Sudo (Critical)

echo "$(whoami) ALL=NOPASSWD:ALL" | sudo tee /etc/sudoers.d/$(whoami)
sudo chmod 440 /etc/sudoers.d/$(whoami)

Why: When running sudo via non-interactive SSH, the terminal waits for password input forever. The command appears to "hang" with no output, no error, no progress. This wastes tokens on retries and confuses the user. With NOPASSWD, all sudo commands execute immediately.

Verify:

sudo whoami
# Should output "root" immediately without asking for password

3.3 SSH Keepalive (Server Side)

sudo bash -c 'echo -e "ClientAliveInterval 60\nClientAliveCountMax 3\nMaxSessions 20" > /etc/ssh/sshd_config.d/keepalive.conf'
sudo systemctl restart ssh

Why: Server-side keepalive complements the Windows client-side config. If the server detects no client activity for too long, it kills the connection. With ClientAliveInterval 60, the server sends a heartbeat every 60 seconds.

3.4 Disable System Version Upgrade

sudo sed -i 's/Prompt=lts/Prompt=never/' /etc/update-manager/release-upgrades

Why: Ubuntu periodically pops up a "Upgrade to 24.04 LTS" notification. Accidentally clicking it will break ROS2 Humble (which is tied to Ubuntu 22.04). Setting Prompt=never disables this notification forever while still allowing normal security updates via apt upgrade.

3.5 SSH Key Login (From Windows)

# On Windows, after Ubuntu SSH is running:
ssh-copy-id xsy@192.168.241.138
# Or manually:
type $env:USERPROFILE\.ssh\id_rsa.pub | ssh ubuntu-vm "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

Why: Without key-based auth, every SSH command requires password input. Non-interactive SSH (used by automation tools) cannot enter passwords and hangs forever.


Phase 4: Quick Verification

After all steps, run this to verify everything works:

ssh ubuntu-vm "sudo whoami && sudo apt update 2>&1 | tail -1 && echo ALL_OK"

Expected output:

root
Reading package lists... Done
ALL_OK

If any step fails, fix it before proceeding to actual development work.


Common Issues & Fixes

Symptom Cause Fix
profile.ps1 forbidden Execution policy Restricted Set-ExecutionPolicy RemoteSigned
Chinese garbled output Console not UTF-8 Add UTF-8 config to profile.ps1
SSH hangs with no output Waiting for password (sudo or SSH) Configure NOPASSWD sudo + SSH key
SSH hangs during long build Connection killed by timeout Add ServerAliveInterval to SSH config
Host key changed after VM reinstall Old host key cached ssh-keygen -R 192.168.241.138
Upgrade to 24.04 popup Default Prompt=lts Prompt=never
Connection refused SSH server not running sudo systemctl start ssh

One-Script Setup (Ubuntu Side)

Save as setup-env.sh on the Ubuntu VM and run after fresh install:

#!/bin/bash
# Phase 1: Passwordless sudo
echo "$(whoami) ALL=NOPASSWD:ALL" | sudo tee /etc/sudoers.d/$(whoami)
sudo chmod 440 /etc/sudoers.d/$(whoami)# Phase 2: SSH keepalive
sudo bash -c 'echo -e "ClientAliveInterval 60\nClientAliveCountMax 3\nMaxSessions 20" > /etc/ssh/sshd_config.d/keepalive.conf'
sudo systemctl restart ssh# Phase 3: Disable version upgrade
sudo sed -i 's/Prompt=lts/Prompt=never/' /etc/update-manager/release-upgrades# Phase 4: Verify
echo ""
echo "=== Verification ==="
echo "Sudo: $(sudo whoami)"
echo "SSH: $(systemctl is-active ssh)"
echo "Upgrade prompt: $(grep Prompt /etc/update-manager/release-upgrades)"
echo "Keepalive: $(cat /etc/ssh/sshd_config.d/keepalive.conf)"
echo ""
echo "DONE. Now run 'ssh-copy-id xsy@192.168.241.138' from Windows."
http://www.jsqmd.com/news/1038750/

相关文章:

  • 2026年6月正规靠谱的武汉同城搬家公司有哪些,居民家庭搬家/公司单位搬迁/长短途搬家搬运,搬家公司一站式解决 - 资讯纵览
  • 2026年6月液压升降机厂家推荐 - 多才菠萝
  • 2026长春防水补漏建筑修缮行业科普:正规服务商甄选指南 - 资讯纵览
  • GitHub Desktop中文界面终极指南:深入解析GitHubDesktop2Chinese架构与实现
  • 如何高效完成OneNote到Markdown的格式转换:专业解决方案指南
  • 武汉空调维修武汉武昌积玉桥空调维修-20206反馈师傅靠谱较多的本地维修 - 资讯纵览
  • 2026年6月武汉搬家别瞎找!本地实测靠谱一站式搬家公司,附近优选、急速上门 - 资讯纵览
  • Audiveris完整教程:10分钟学会免费乐谱识别,让纸质乐谱变数字音乐
  • 2026年6月郑州学生毕业搬家、长短途搬家、居民家庭搬家、公司单位搬迁,同城搬家搬运专业搬家公司联系方式与选择指南 - 资讯纵览
  • 3步搞定ESP32物联网开发:Arduino核心快速配置指南
  • 【2026年6月】导轨式货梯厂家、液压升降机、升降平台推荐指南 - 多才菠萝
  • 学了半年日语却开不了口?不是你不行,是你缺了一个“能接住你”的环境 - 资讯纵览
  • MCP1826 LDO电源设计:1A大电流与120µA低静态功耗的工程实践
  • 南京本地服务商做AI获客,为什么要先做品牌知识库?|地基逻辑拆解 - 资讯纵览
  • 华硕笔记本风扇异常?5分钟终极修复指南
  • 2026免费在线抠图软件推荐!无需下载网页版小程序保姆级使用教程
  • 雀魂牌谱屋:用数据思维重新定义麻将竞技体验
  • Gemini多模态原生架构解析:跨模态对齐与推理链解耦
  • 石家庄众成学校联系电话 校区地址 官方联系方式 - 资讯纵览
  • 武汉搬家公司怎么选,全城各区全品类详细服务大全、专业搬家公司联系方式与选择指南,附近优选、急速上门 - 资讯纵览
  • 【毕业设计】基于 Django+Vue 的通信营业厅资费管控系统的设计与实现 基于 Django+Vue 的电信套餐资费查询核算平台(源码+文档+远程调试,全bao定制等)
  • 2026年6月正规靠谱的郑州同城搬家公司有哪些,居民家庭搬家/公司单位搬迁/长短途搬家搬运,搬家公司一站式解决 - 资讯纵览
  • Office RibbonX Editor:重塑Office自定义界面的现代化工具
  • 2026 佛山靠谱的卫生间防水补漏公司推荐 top5 推荐 - 防水资讯
  • 2026 家庭影院定制 TOP 榜单 | 私人影院哪家好 | 全国口碑厂家实力之选 -- 夜色空间 - 资讯纵览
  • 【2026年6月】升降台厂家、高空作业平台、液压升降机推荐指南 - 多才菠萝
  • 同城运电瓶车选哪家 2026本地推荐 - 快递物流资讯
  • 2026年武汉靠谱的搬家公司:定制化搬家方案与无临时加价服务商家测评与推荐 - 资讯纵览
  • 轻量级AI疫情预测系统在亚洲基层的落地实践
  • AI生图范式转移:从端到端黑箱到意图优先的结构化生成