機器人實踐課程鏡像分享及使用說明(Arduino+ROS1+ROS2+Gazebo+SLAM+...)

經過5年嘗試和努力,在吸取indigo、kinetic版本經驗後,融合Arduino、ROS1、ROS2、Gazebo和SLAM的適用機器人愛好者的實踐課程鏡像嚐鮮版(bug是免不了的!_!)終於完成了。

非常感謝給我寶貴建議的學生、老師以及熱心的博客朋友們,祝福大家2020年新春快樂。


留言提出建議和需求一經採納,就有機會獲贈如下小禮物(不要私信哦,太多了,無法回答了,並且其他朋友看不到):

 

 限量版,只供贈送,內置本文鏡像和相關資料。


距離上一次鏡像發佈(2016年)已經快4年了,在瞭解和使用前推薦閱讀,如獲點贊或打賞感激不盡:

唯一需要自備的硬件爲Arduino及其相關配件:

製作遙控ROS機器人的手柄或IoT物聯網傳感器 


機器人實踐課程鏡像分享及使用說明分爲6大部分,分別爲:

  1. 鏡像使用說明

  2. Arduino案例

  3. ROS1案例

  4. ROS2案例

  5. Gazebo案例

  6. SLAM案例


 鏡像依據本科課程製作,以項目式案例教學和實踐爲主,適用上述課程(點擊可打開鏈接,瞭解詳細內容):

分別涵蓋在不同時期發佈的教學鏡像中,經過學生使用、實踐和反饋,逐步改進和完善,但由於水平有限和能力不足,依然存在不少問題,可自行研究解決。


第一部分:鏡像使用說明

下載鏈接:https://share.weiyun.com/5yS1hT6 密碼:rmxebn

製作iso鏡像U盤啓動使用rufus-3.8p,可以直接去官網下載,iso鏡像文件較大3.54GB。

實踐課已經詳細講解過使用方式,需要用管理員權限啓動rufus,具體流程如下圖所示。

支持legacy和UEFI雙模式。

製作速度依據U盤讀寫速度而定,SLC盤小於2分鐘,年代久遠的古董盤超過20分鐘也正常。

做好後的課程學習盤內部文件如下圖所示:

在開機BIOS設置爲U盤啓動,或者直接快捷方式更改啓動順序設定U盤爲先。

此處需注意,legacy和UEFI啓動界面略有差異,鏡像支持安裝:

打開終端,輸入$ sudo ubiquity    輸入密碼:ros

此鏡像爲個人上課使用,測試時間2018.6-2020.1,用戶名爲博客名,不喜歡可以隨意修改。

測試過10+型號筆記本和臺式機,兼容性良好,也有部分電腦需要專業級設置,屬於個別案例。

測試截圖如下:

1. U盤系統:

較新配置臺式機

較舊配置臺式機

2. U盤鏡像:

較新配置筆記本

較舊配置筆記本

Desktop

Arduino


# ROS 1.0 melodic or ROS 2.0 Dashing
echo Hello, ROS 1.0 or ROS 2.0? 1=Melodic 2=Dashing 
read ROS
if (($ROS==1));then
source /opt/ros/melodic/setup.bash
#export ROS_PACKAGE_PATH=/home/relaybot/RobTool/ROS1/Wiki/src:/home/relaybot/RobTool/Cozmo/ros/src:$ROS_PACKAGE_PATH
#source /home/relaybot/RobTool/ROS1/Wiki/devel/setup.bash
#export ROS_MASTER_URI=http://192.168.1.100:11311
#export ROS_IP=192.168.1.100
echo "Melodic"
elif (($ROS==2));then
source /opt/ros/dashing/setup.bash
echo "Dashing"
else
echo "Non-ROS"
fi

# turtlebot3 model env TURTLEBOT3_MODEL  model type [burger, waffle, waffle_pi]" name="model"
export TURTLEBOT3_MODEL=waffle

ROS1+ROS2

Gazebo

SLAM    高翔 等著, 視覺SLAM十四講:從理論到實踐(第2版)


第二部分:Arduino案例

  • AD0-LED13
// These constants won't change. They're used to give names to the pins used:
int i=0,j=0,stime=32,sloop=0;
const int atime=16;
const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to

int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)

void setup() {
  // initialize serial communications at 9600 bps:
  pinMode(LED_BUILTIN, OUTPUT);  
  Serial.begin(9600);
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, atime);
  // change the analog out value:
  stime=outputValue;
  // print the results to the Serial Monitor:
  //Serial.print("sensor = ");
  //Serial.print(sensorValue);
  //Serial.print("\t output = ");
  //Serial.println(outputValue);
  ledfade(stime);
  // wait 2 milliseconds before the next loop for the analog-to-digital
  // converter to settle after the last reading:
}

void ledfade(int i)
{
      digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(i);                          // wait for a second
      digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
      delay(atime-i);                    // wait for a second
}
  • AD3&4&5-/cmd_vel(ROS)
#if (ARDUINO >= 100)
 #include <Arduino.h>
#else
 #include <WProgram.h>
#endif
#include <ros.h>
#include <rosserial_arduino/Adc.h>
#include <geometry_msgs/Twist.h>

ros::NodeHandle nh;

rosserial_arduino::Adc adc_msg;
geometry_msgs::Twist twist_msg;
ros::Publisher p("adc", &adc_msg);
ros::Publisher t("cmd_vel", &twist_msg); 
//turtlesim turtle1/cmd_vel
//turtlebot3 cmd_vel
//husky cmd_vel
void setup()
{ 
  pinMode(13, OUTPUT);
  nh.initNode();
  nh.advertise(p);
  nh.advertise(t);
}

//We average the analog reading to elminate some of the noise
int averageAnalog(int pin){
  int v=0;
  for(int i=0; i<4; i++) v+= analogRead(pin);
  return v/4;
}

long adc_timer;
int x_mid=600,y_mid=600,x_now=600,y_now=600;
int adc_init=100;
void loop()
{
  adc_msg.adc0 = averageAnalog(0);
  adc_msg.adc1 = averageAnalog(1);
  adc_msg.adc2 = averageAnalog(2);
  adc_msg.adc3 = averageAnalog(3);
  adc_msg.adc4 = averageAnalog(4);
  adc_msg.adc5 = averageAnalog(5);
  x_now=adc_msg.adc5-x_mid;
  y_now=adc_msg.adc4-y_mid;
  adc_init=adc_msg.adc3;
  if(adc_init<10){
    x_mid=adc_msg.adc5;
    y_mid=adc_msg.adc4;
  }
  if(x_now>0)
    twist_msg.linear.x=map(x_now,0,1023-x_mid,0,255);
  else
    twist_msg.linear.x=map(x_now,-x_mid,0,-255,0);
  if(y_now>0)
    twist_msg.angular.z=map(y_now,0,1023-y_mid,0,255);
  else
    twist_msg.angular.z=map(y_now,-y_mid,0,-255,0); 

  twist_msg.linear.x=twist_msg.linear.x/(1024.0-adc_msg.adc0)/4.0;
  twist_msg.angular.z=-twist_msg.angular.z/(1024.0-adc_msg.adc0);
         
  p.publish(&adc_msg);
  t.publish(&twist_msg);
  nh.spinOnce();
//  delay(1);
}

C++&Arduino+ROS


第三部分:ROS1案例

  • turtlesim+action


roscore

rosrun turtlesim turtlesim_node

rosrun turtle_actionlib shape_server

rosrun turtle_actionlib shape_client

rqt_graph
  • turtlebot3+rqt_image_view


roslaunch turtlebot3_gazebo turtlebot3_world.launch

rqt_image_view

第四部分:ROS2案例

  • turtlesim+action+rqt

ros2 run turtlesim turtlesim_node

ros2 run turtlesim turtle_teleop_key

rqt
  • dummy_robot_bringup+rviz2

ros2 launch dummy_robot_bringup dummy_robot_bringup.launch.py

rviz2

demo.rviz

Panels:
  - Class: rviz_common/Displays
    Help Height: 78
    Name: Displays
    Property Tree Widget:
      Expanded:
        - /Global Options1
        - /Status1
      Splitter Ratio: 0.5
    Tree Height: 435
  - Class: rviz_common/Selection
    Name: Selection
  - Class: rviz_common/Tool Properties
    Expanded:
      - /2D Nav Goal1
      - /Publish Point1
    Name: Tool Properties
    Splitter Ratio: 0.5886790156364441
  - Class: rviz_common/Views
    Expanded:
      - /Current View1
    Name: Views
    Splitter Ratio: 0.5
Visualization Manager:
  Class: ""
  Displays:
    - Alpha: 0.5
      Cell Size: 1
      Class: rviz_default_plugins/Grid
      Color: 160; 160; 164
      Enabled: true
      Line Style:
        Line Width: 0.029999999329447746
        Value: Lines
      Name: Grid
      Normal Cell Count: 0
      Offset:
        X: 0
        Y: 0
        Z: 0
      Plane: XY
      Plane Cell Count: 10
      Reference Frame: <Fixed Frame>
      Value: true
    - Alpha: 0.699999988079071
      Class: rviz_default_plugins/Map
      Color Scheme: map
      Draw Behind: false
      Enabled: true
      Name: Map
      Topic: /map
      Unreliable: false
      Use Timestamp: false
      Value: true
    - Alpha: 1
      Autocompute Intensity Bounds: true
      Autocompute Value Bounds:
        Max Value: 10
        Min Value: -10
        Value: true
      Axis: Z
      Channel Name: intensity
      Class: rviz_default_plugins/LaserScan
      Color: 255; 255; 255
      Color Transformer: Intensity
      Decay Time: 0
      Enabled: true
      Invert Rainbow: false
      Max Color: 255; 255; 255
      Max Intensity: 4096
      Min Color: 0; 0; 0
      Min Intensity: 0
      Name: LaserScan
      Position Transformer: XYZ
      Queue Size: 10
      Selectable: true
      Size (Pixels): 3
      Size (m): 0.009999999776482582
      Style: Flat Squares
      Topic: /scan
      Unreliable: false
      Use Fixed Frame: true
      Use rainbow: true
      Value: true
    - Alpha: 1
      Axes Length: 1
      Axes Radius: 0.10000000149011612
      Class: rviz_default_plugins/Pose
      Color: 255; 25; 0
      Enabled: true
      Head Length: 0.30000001192092896
      Head Radius: 0.10000000149011612
      Name: Pose
      Shaft Length: 1
      Shaft Radius: 0.05000000074505806
      Shape: Arrow
      Topic: /move_base_simple/goal
      Unreliable: false
      Value: true
    - Class: rviz_default_plugins/TF
      Enabled: true
      Frame Timeout: 15
      Frames:
        All Enabled: true
      Marker Scale: 1
      Name: TF
      Show Arrows: true
      Show Axes: true
      Show Names: false
      Tree:
        {}
      Update Interval: 0
      Value: true
    - Alpha: 1
      Class: rviz_default_plugins/RobotModel
      Collision Enabled: false
      Description File: ""
      Description Source: Topic
      Description Topic: ""
      Enabled: true
      Links:
        All Links Enabled: true
        Expand Joint Details: false
        Expand Link Details: false
        Expand Tree: false
        Link Tree Style: ""
      Name: RobotModel
      TF Prefix: ""
      Unreliable: false
      Update Interval: 0
      Value: true
      Visual Enabled: true
  Enabled: true
  Global Options:
    Background Color: 48; 48; 48
    Fixed Frame: world
    Frame Rate: 30
  Name: root
  Tools:
    - Class: rviz_default_plugins/MoveCamera
    - Class: rviz_default_plugins/Select
    - Class: rviz_default_plugins/FocusCamera
    - Class: rviz_default_plugins/Measure
      Line color: 128; 128; 0
    - Class: rviz_default_plugins/SetInitialPose
      Topic: /initialpose
    - Class: rviz_default_plugins/SetGoal
      Topic: /move_base_simple/goal
    - Class: rviz_default_plugins/PublishPoint
      Single click: true
      Topic: /clicked_point
  Transformation:
    Current:
      Class: rviz_default_plugins/TF
  Value: true
  Views:
    Current:
      Class: rviz_default_plugins/Orbit
      Distance: 8.303964614868164
      Enable Stereo Rendering:
        Stereo Eye Separation: 0.05999999865889549
        Stereo Focal Distance: 1
        Swap Stereo Eyes: false
        Value: false
      Focal Point:
        X: 0.5349314212799072
        Y: -1.8630497455596924
        Z: 0.5543326139450073
      Focal Shape Fixed Size: true
      Focal Shape Size: 0.05000000074505806
      Invert Z Axis: false
      Name: Current View
      Near Clip Distance: 0.009999999776482582
      Pitch: 0.7453981041908264
      Target Frame: <Fixed Frame>
      Value: Orbit (rviz)
      Yaw: 1.8422259092330933
    Saved: ~
Window Geometry:
  Displays:
    collapsed: false
  Height: 664
  Hide Left Dock: false
  Hide Right Dock: true
  QMainWindow State: 000000ff00000000fd0000000400000000000001560000023efc0200000008fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000005c00fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000003d0000023e000000c900fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261000000010000010f0000023efc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a00560069006500770073000000003d0000023e000000a400fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000004420000003efc0100000002fb0000000800540069006d00650100000000000004420000000000000000fb0000000800540069006d00650100000000000004500000000000000000000002a40000023e00000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
  Selection:
    collapsed: false
  Tool Properties:
    collapsed: false
  Views:
    collapsed: true
  Width: 1024
  X: 0
  Y: 27

第五部分:Gazebo案例

ros2 topic pub /demo/cmd_demo geometry_msgs/Twist '{linear: {x: 0.2}}' -1

第六部分:SLAM案例

高翔 等著, 視覺SLAM十四講:從理論到實踐(第2版)


 ROS:~$ tree -L 3

.
├── Arduino
│   ├── course
│   │   ├── ADCdemo
│   │   ├── AnalogInOutLEDdemo
│   │   ├── AnalogInOutLEDtimedemo
│   │   ├── AnalogInputdemo
│   │   ├── Blinkdemo
│   │   ├── blinkmicrosdemo
│   │   ├── Buttondemo
│   │   ├── Controldemo
│   │   ├── Controlplusdemo
│   │   ├── Controlplusdemo2
│   │   ├── DHTtesterDemo
│   │   ├── dueControldemo
│   │   ├── HCSR04demo
│   │   ├── Knobdemo
│   │   ├── motordemo
│   │   ├── robotdemo
│   │   └── tonePitchFollowerdemo
│   └── libraries
│       ├── Adafruit_Circuit_Playground
│       ├── Adafruit_Unified_Sensor
│       ├── DHT_sensor_library
│       ├── readme.txt
│       ├── Rosserial_Arduino_Library
│       └── SD
├── Desktop
│   └── demo.rviz
├── Documents
│   ├── Arduino
│   │   ├── imutovel.py
│   │   ├── Integrating Arduino-Based Educational Mobile Robots in ROS.pdf
│   │   ├── LabLecture3 Hardware interfacing Arduino.pdf
│   │   ├── note191125.md
│   │   ├── Programming Your First Robot - EE100 Fall 2016.pdf
│   │   └── 機器人控制器編程-總結篇.pdf
│   └── Fritzing
│       ├── bins
│       └── parts
├── Downloads
│   ├── android_camera_imu.apk
│   ├── pinguybuilder_5.1-8_all.deb
│   ├── pycozmo-master.zip
│   └── slambook2-master.zip
├── Music
├── Pictures
│   ├── Screenshot from 2020-01-07 14-44-21.png
│   ├── Screenshot from 2020-01-07 14-51-44.png
│   ├── Screenshot from 2020-01-07 14-55-28.png
│   ├── Screenshot from 2020-01-07 14-56-49.png
│   ├── Screenshot from 2020-01-07 15-05-16.png
│   ├── Screenshot from 2020-01-07 15-18-33.png
│   ├── Screenshot from 2020-01-07 15-54-15.png
│   ├── Screenshot from 2020-01-07 15-57-50.png
│   ├── Screenshot from 2020-01-07 16-08-05.png
│   ├── Screenshot from 2020-01-07 16-26-15.png
│   └── Wallpapers
│       └── ubunturobot.png
├── Public
├── Roft
│   ├── arduino
│   │   └── arduino-1.8.10
│   ├── cozmo_ros2_ws
│   │   ├── build
│   │   ├── install
│   │   ├── log
│   │   └── src
│   ├── Micro-XRCE-DDS-Agent
│   │   ├── agent.refs
│   │   ├── build
│   │   ├── cmake
│   │   ├── CMakeLists.txt
│   │   ├── CTestJenkins.cmake
│   │   ├── Dockerfile
│   │   ├── docs
│   │   ├── include
│   │   ├── LICENSE
│   │   ├── microxrce_agent.cpp
│   │   ├── README.md
│   │   ├── src
│   │   ├── test
│   │   ├── thirdparty
│   │   ├── utils
│   │   └── valgrind.supp
│   ├── opencv-4.1.2
│   │   ├── 3rdparty
│   │   ├── apps
│   │   ├── build
│   │   ├── cmake
│   │   ├── CMakeLists.txt
│   │   ├── CONTRIBUTING.md
│   │   ├── data
│   │   ├── doc
│   │   ├── include
│   │   ├── LICENSE
│   │   ├── modules
│   │   ├── platforms
│   │   ├── README.md
│   │   └── samples
│   └── tello_ros2_ws
│       ├── build
│       ├── install
│       ├── log
│       └── src
├── SLAM
│   └── slambook2
│       ├── ch10
│       ├── ch11
│       ├── ch12
│       ├── ch13
│       ├── ch2
│       ├── ch3
│       ├── ch4
│       ├── ch5
│       ├── ch6
│       ├── ch7
│       ├── ch8
│       ├── ch9
│       ├── errata.cls
│       ├── errata.pdf
│       ├── errata.tex
│       ├── figures
│       ├── LICENSE
│       └── README.md
├── Templates
└── Videos

2020-01-07


~Fin~





 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章