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

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

akio
September 14, 2018

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

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

akio

September 14, 2018
Tweet

More Decks by akio

Other Decks in Technology

Transcript

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

    Institute • ϞόΠϧϚχϐϡϨʔγϣϯϩϘοτͷݚڀ։ൃʹैࣄ • GitHub: http://github.com/akio • ࠓ೔͸ݸਓతͳOSS׆ಈͷ࿩Λ͠·͢
  2. 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ͳͲ
  3. ಈػ • 2013౰࣌ɺROS։ൃਓࡐͷҭ੒ʹ೰ΜͰ͍ͨ • C++ • ෳࡶͳݴޠ࢓༷ • Python/MatlabͳͲ͔Βདྷͨਓͷϋʔυϧ͕ߴ͍ •

    Cݴޠܦݧऀ͕৽֓೦ΛֶͿͷ΋೉͍͠ʢOOPɺδΣωϦοΫϓϩάϥϛϯά౳ʣ • Python • ֶशίετ௿͍ • ੑೳ͕ඞཁʹͳΔͱ݁ہC/C++/CythonͳͲΛॻ͔͟Δ͑ͳ͘ͳͬͨΓ͢Δ
  4. ̎̌̍̏౰࣌ͷީิൺֱ • Java • rosjava͕͢Ͱʹଘࡏ • ωΠςΟϒίϯύΠϧͰ͖ͳ͍ • ύοέʔδ഑෍͕ͭΒ͍ •

    Go • Better C తͳจ๏ • ػೳ͕ߜΒΕ֮͑Δ͜ͱ͕গͳ͍ • ωΠςΟϒίϯύΠϧͰ݁ߏ଎͍ • GC͕ϝϞϦͷੈ࿩Λͯ͘͠ΕΔ • Rust • ଎͍ɺ҆શɺؾ͍͍࣋ͪ • ࣗ෼͕ٻΊ͍ͯͨ΋ͷ͕େମ͋Δ • ͋Γ͗ͯ͢΍ͬͺΓֶशίετ͕ߴ ͍ͷͰ͸‥.ʁ • Julia • ॻ͖΍ͯ͘͢଎ͯ͘࠷ڧʹݟ͑Δ • Ͱ΋౰࣌Ͱ͖ͨ͹͔ΓͰ৭ʑػೳ͕ ଍Γͳ͔ͬͨ • ฒྻॲཧ͕ͭΒͦ͏
  5. ࠷ۙͷΞοϓσʔτ(2018) • RemappingΛ࣮૷ • ΫϥΠΞϯτϥΠϒϥϦͷػೳ͕Ұ௨ΓͦΖͬͨ • v1.0.0ͷ४උ͕੔ͬͨʁ • ಠཱͨ͠msg/srvίʔυδΣωϨʔλΛ࣮૷ •

    Good bye, Catkin and CMake! • Go੡ͷίʔυδΣωϨʔλΛ࣮૷ͯ͠ Pure Go ύοέʔδԽ • Go generateͱvendoringΛར༻ʢޙड़ʣ
  6. ϝοηʔδੜ੒ • 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ίʔυ͕ੜ੒
  7. Πϯετʔϧ 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"
  8. 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) } }
  9. 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() }
  10. 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() }
  11. 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) }
  12. 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") }
  13. ϩϘοτ։ൃʹ࢖͑ΔGoϥΠϒϥϦͷ঺հ • GoCV • OpenCVͷGoόΠϯσΟϯά • Tensorflow • ެࣜͷGoόΠϯσΟϯά͕ ͋Δ

    • GoNum • Numpyతͳ਺஋ܭࢉϥΠϒϥ Ϧ • gobot • ओʹIoTͳ֎෦σόΠεͱͷI/Oॲཧϥ ΠϒϥϦ • g3n • ήʔϜΤϯδϯɺՄࢹԽͳͲʹ࢖͑Δ • GoRO • ৭ʑ଍Γͳ͍ͷͰࣗ෼Ͱ࡞Γ࢝Ίͨ • https://github.com/akio/goro • ·ͩURDF parser ͘Β͍͔͠ͳ͍