Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Go言語によるROSプログラミング

5e8224dd66eb7871fb05672ba08c7275?s=47 akio
September 14, 2018

 Go言語によるROSプログラミング

Slides used in my talk about ROS client library implementation for ROS.

5e8224dd66eb7871fb05672ba08c7275?s=128

akio

September 14, 2018
Tweet

More Decks by akio

Other Decks in Technology

Transcript

  1. GoݴޠʹΑΔROSϓϩάϥϛϯά https://github.com/akio/rosgo.git

  2. ࣗݾ঺հ

  3. ࣗݾ঺հ • Akiyoshi(Akio) Ochiai • Sr Engineer @ Toyota Research

    Institute • ϞόΠϧϚχϐϡϨʔγϣϯϩϘοτͷݚڀ։ൃʹैࣄ • GitHub: http://github.com/akio • ࠓ೔͸ݸਓతͳOSS׆ಈͷ࿩Λ͠·͢
  4. ROSؔ܎Ͱ࡞ͬͨ΋ͷ • rosrb • ROSͷRubyΫϥΠΞϯτϥΠϒϥϦ • ౰࣌ಉ͡ձࣾʹ͍ͨ@OTLࢯͱ͔Ϳ্ͬͨʹग़஗ΕͯϘπ • vim-ctrlp-ros •

    Vim Ctrl-P ROS ϓϥάΠϯ • msg/srv/actionͳͲΛVim͔ΒΠϯΫϦϝϯλϧαʔν • RosCraft • MinecraftΛROS͔Β੍ޚͰ͖Δͧ • Կ͕͔ͨͬͨ͠ͷ͔Α͘Θ͔Βͳ͍ • fluent_logger_ros • ROSͷϩάΛfluentdʹྲྀ͠ࠐΉখ඼ • mask_rcnn_ros • Advent CalendarͷωλͷͨΊʹ։ൃ • menoh_ros • ONNXΛROSͷը૾ॲཧύΠϓϥΠϯʹυϩοϓΠϯ • rosgo • ࠓճൃද͢Δ಺༰ • ͦͷଞ׆ಈ • MoveIt! ΁ͷPRɺϝϯςφʔձٞࢀՃͳͲ • ROSίΞύοέʔδ΁ͷPRͳͲ
  5. ެ։ROS͓࢓ࣄ • ։ൃνʔϜͷڠྗͷ΋ͱɺτϤλHSRͷϩϘοτϞσϧϑΝΠϧΛΦʔϓϯιʔεԽ͠·ͨ͠ • hsr_description • https://github.com/ToyotaResearchInstitute/hsr_description • hsr_meshes •

    https://github.com/ToyotaResearchInstitute/hsr_meshes https://github.com/OTL/gear ROSҎ֎Ͱͷ׆༻ྫ
  6. Why Go?

  7. ಈػ • 2013౰࣌ɺROS։ൃਓࡐͷҭ੒ʹ೰ΜͰ͍ͨ • C++ • ෳࡶͳݴޠ࢓༷ • Python/MatlabͳͲ͔Βདྷͨਓͷϋʔυϧ͕ߴ͍ •

    Cݴޠܦݧऀ͕৽֓೦ΛֶͿͷ΋೉͍͠ʢOOPɺδΣωϦοΫϓϩάϥϛϯά౳ʣ • Python • ֶशίετ௿͍ • ੑೳ͕ඞཁʹͳΔͱ݁ہC/C++/CythonͳͲΛॻ͔͟Δ͑ͳ͘ͳͬͨΓ͢Δ
  8. ֮͑΍͍͢ ͦͦ͜͜଎͍ ͋Δఔ౓ϦΞϧλΠϜੑͷ͋Δ ϓϩάϥϛϯάݴޠ͸ͳ͍͔ʁ

  9. ̎̌̍̏౰࣌ͷީิൺֱ • Java • rosjava͕͢Ͱʹଘࡏ • ωΠςΟϒίϯύΠϧͰ͖ͳ͍ • ύοέʔδ഑෍͕ͭΒ͍ •

    Go • Better C తͳจ๏ • ػೳ͕ߜΒΕ֮͑Δ͜ͱ͕গͳ͍ • ωΠςΟϒίϯύΠϧͰ݁ߏ଎͍ • GC͕ϝϞϦͷੈ࿩Λͯ͘͠ΕΔ • Rust • ଎͍ɺ҆શɺؾ͍͍࣋ͪ • ࣗ෼͕ٻΊ͍ͯͨ΋ͷ͕େମ͋Δ • ͋Γ͗ͯ͢΍ͬͺΓֶशίετ͕ߴ ͍ͷͰ͸‥.ʁ • Julia • ॻ͖΍ͯ͘͢଎ͯ͘࠷ڧʹݟ͑Δ • Ͱ΋౰࣌Ͱ͖ͨ͹͔ΓͰ৭ʑػೳ͕ ଍Γͳ͔ͬͨ • ฒྻॲཧ͕ͭΒͦ͏
  10. ͦͷଞͷڧΈ • ڧྗͳ։ൃମ੍ʢby Google) • ௿ϨΠςϯγͳΨϕʔδίϨΫγϣϯʢޙड़) • ๛෋ͳ։ൃ࣮੷(DockerͳͲ) • σϑΥϧτͰ੩తϦϯΫ͞ΕͨγϯάϧόΠφϦΛੜ੒

    • πʔϧ։ൃͳͲʹ޲͘ • σϓϩΠ͕؆୯
  11. αϒϛϦඵGC ग़యɿhttps://twitter.com/brianhatfield/status/804355831080751104

  12. ऑΈ • ϝϞϦΛେྔʹ֬อɾղ์͢ΔΑ͏ͳ࢖͍ํΛ͢Δͱεϧʔϓοτ͕ѱԽ • Պֶٕज़ܭࢉ༻ͷϥΠϒϥϦ͕গͳ͍ʢগͣͭ͠૿͖͑ͯͨɺޙͰ঺հʣ • ԋࢉࢠΦʔόʔϩʔυ͕ͳ͍ʢˢʹͪΐͬͱӨڹʣ • όΠφϦαΠζ͕େ͖͘ͳΓ͕ͪ

  13. GoͰROSϓϩάϥϛϯάͰ͖ΔΑ͏ʹ͠Α͏

  14. rosgo ॳظ։ൃ൛(2013) • ͕Μ͹ΓϙΠϯτ • XMLRPCϥΠϒϥϦ͕ͳ͔ͬͨͷͰࣗ෼Ͱ࣮૷ͨ͠ • CatkinπʔϧνΣʔϯʹ౷߹

  15. ࠷ۙͷΞοϓσʔτ(2018) • RemappingΛ࣮૷ • ΫϥΠΞϯτϥΠϒϥϦͷػೳ͕Ұ௨ΓͦΖͬͨ • v1.0.0ͷ४උ͕੔ͬͨʁ • ಠཱͨ͠msg/srvίʔυδΣωϨʔλΛ࣮૷ •

    Good bye, Catkin and CMake! • Go੡ͷίʔυδΣωϨʔλΛ࣮૷ͯ͠ Pure Go ύοέʔδԽ • Go generateͱvendoringΛར༻ʢޙड़ʣ
  16. ϝοηʔδੜ੒ • Goͷػೳ go generate (v1.4+)ɹͱ vendorng (v1.5+)Λ׆༻ • ιʔείʔυதʹҎԼͷΑ͏ʹॻ͍͓ͯ͘

    • //go:generate gengo msg your_pkg/MsgType • $ go generate <GO_PKG_NAME> Λ࣮ߦ • ͢Δͱɺ$GOPATH/your_pkg/vendorҎԼʹGoίʔυ͕ੜ੒
  17. rosgo ίʔυྫ

  18. Πϯετʔϧ 1. GoͷΠϯετʔϧ 2. $ go get -u github.com/akio/rosgo/ros 3.

    $ go install github.com/akio/rosgo/gengo 4. import “github.com/akio/rosgo/ros"
  19. Publisher package main //go:generate gengo msg std_msgs/String import ( "fmt"

    "github.com/akio/rosgo/ros" "os" "std_msgs" "time" ) func main() { node, _ := ros.NewNode("/talker", os.Args) defer node.Shutdown() pub, _ := node.NewPublisher("/chatter", std_msgs.MsgString) for node.OK() { node.SpinOnce() var msg std_msgs.String msg.Data = fmt.Sprintf("hello %s", time.Now().String()) pub.Publish(&msg) time.Sleep(time.Second) } }
  20. Subscriber package main //go:generate gengo msg std_msgs/String import ( "fmt"

    "github.com/akio/rosgo/ros" "os" "std_msgs" ) func callback(msg *std_msgs.String) { fmt.Printf("Received: %s\n", msg.Data) } func main() { node, _ := ros.NewNode("/listener", os.Args) defer node.Shutdown() node.NewSubscriber("/chatter", std_msgs.MsgString, callback) node.Spin() }
  21. Example: Service Server package main //go:generate gengo srv rospy_tutorials/AddTwoInts import

    ( "fmt" "github.com/akio/rosgo/ros" "os" "rospy_tutorials" ) func callback(srv *rospy_tutorials.AddTwoInts) error { srv.Response.Sum = srv.Request.A + srv.Request.B fmt.Printf("%d + %d = %d\n", srv.Request.A, srv.Request.B, srv.Response.Sum) return nil } func main() { node, _ := ros.NewNode("server", os.Args) defer node.Shutdown() server, _ := node.NewServiceServer("/add_two_ints", rospy_tutorials.SrvAddTwoInts, callback) defer server.Shutdown() node.Spin() }
  22. Service Client package main //go:generate gengo srv rospy_tutorials/AddTwoInts import (

    "fmt" "github.com/akio/rosgo/ros" "os" "rospy_tutorials" ) func main() { node, _ := ros.NewNode("client", os.Args) defer node.Shutdown() cli, _ := node.NewServiceClient("/add_two_ints", rospy_tutorials.SrvAddTwoInts) defer cli.Shutdown() var srv rospy_tutorials.AddTwoInts srv.Request.A = 1 srv.Request.B = 2 _ = cli.Call(&srv) fmt.Printf("%d + %d = %d\n", srv.Request.A, srv.Request.B, srv.Response.Sum) }
  23. Parameters package main import ( "fmt" "github.com/akio/rosgo/ros" "log" "os" )

    func main() { node, _ := ros.NewNode("/test_param", os.Args) defer node.Shutdown() hasParam, _ := node.HasParam("/rosdistro") param, _ := node.GetParam("/rosdistro") err := node.SetParam("/test_param", 42) param, _ := node.GetParam("/test_param") err := node.DeleteParam("/test_param") foundKey, _ := node.SearchParam(“/rosdistro") }
  24. ͜Ε͔Β

  25. ػೳ௥Ճ • Action Client/Server • TF • ଞʁ

  26. ϩϘοτ։ൃʹ࢖͑ΔGoϥΠϒϥϦͷ঺հ • GoCV • OpenCVͷGoόΠϯσΟϯά • Tensorflow • ެࣜͷGoόΠϯσΟϯά͕ ͋Δ

    • GoNum • Numpyతͳ਺஋ܭࢉϥΠϒϥ Ϧ • gobot • ओʹIoTͳ֎෦σόΠεͱͷI/Oॲཧϥ ΠϒϥϦ • g3n • ήʔϜΤϯδϯɺՄࢹԽͳͲʹ࢖͑Δ • GoRO • ৭ʑ଍Γͳ͍ͷͰࣗ෼Ͱ࡞Γ࢝Ίͨ • https://github.com/akio/goro • ·ͩURDF parser ͘Β͍͔͠ͳ͍
  27. Go 2 • GoݴޠͷΧϯϑΝϨϯε GopherCon2018ʹͯɺGo 2ͷυϥϑτ͕ൃද • Τϥʔॲཧจ๏ͷվྑ • δΣωϦΫεͷ௥Ճ

  28. ROS2 • DDSΛ࣮૷͢Δͷ͸େมͦ͏ • rclΛcgoͰϥοϓ͢Δʁ

  29. ·ͱΊ • GoݴޠͰ࢖͑ΔROSΫϥΠΞϯτϥΠϒϥϦΛ։ൃͨ͠ • ฏ੒͕ऴΘΔલʹൃදͰ͖ͯྑ͔ͬͨ

  30. Thank you! https://github.com/akio/rosgo.git