{"id":218,"date":"2018-04-15T09:00:12","date_gmt":"2018-04-15T09:00:12","guid":{"rendered":"http:\/\/www.hardwarehacker.co.uk\/blog\/?p=218"},"modified":"2021-04-07T08:33:10","modified_gmt":"2021-04-07T08:33:10","slug":"a-gopher-in-a-tiger","status":"publish","type":"post","link":"https:\/\/www.hardwarehacker.co.uk\/blog\/a-gopher-in-a-tiger\/","title":{"rendered":"A Gopher in a Tiger?"},"content":{"rendered":"<figure id=\"attachment_223\" aria-describedby=\"caption-attachment-223\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.hardwarehacker.co.uk\/blog\/wp-content\/uploads\/2018\/04\/Golang.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-223\" src=\"http:\/\/www.hardwarehacker.co.uk\/blog\/wp-content\/uploads\/2018\/04\/Golang-300x108.png\" alt=\"\" width=\"300\" height=\"108\" srcset=\"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-content\/uploads\/2018\/04\/Golang-300x108.png 300w, https:\/\/www.hardwarehacker.co.uk\/blog\/wp-content\/uploads\/2018\/04\/Golang-768x276.png 768w, https:\/\/www.hardwarehacker.co.uk\/blog\/wp-content\/uploads\/2018\/04\/Golang.png 800w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-223\" class=\"wp-caption-text\">Golang mascot, Renee French<\/figcaption><\/figure>\n<p>In the past, we&#8217;ve used Python and C++ for our robots but this year we switched to <a href=\"https:\/\/golang.org\/\">Go<\/a>.\u00a0 Why the change?\u00a0 <del>It seemed like a good idea at the time<\/del><\/p>\n<p>To be honest, the main reason was that I signed up to lead the coding effort this year.\u00a0 I haven&#8217;t had much C++\/Qt experience (so it wasn&#8217;t easy for me to pick up last year&#8217;s code) but I&#8217;ve been working in Go in my day job for a couple of years;\u00a0 I enjoy working with Go and the language has some features that are appealing for building robots:<\/p>\n<ul>\n<li>&#8220;Naturally&#8221; written Go is just plain faster than &#8220;naturally&#8221; written Python (by some margin).<\/li>\n<li>Go can take advantage of more than one core by running multiple goroutines at once (and the computer scientist in me can&#8217;t resist a bit of CSP). The normal Python interpreter is limited to one core.<\/li>\n<li>It <em>felt\u00a0<\/em>like a good choice because it sits at the right level, giving access to low-level primitives (like pointers and structs) for interfacing with C and hardware while also offering garbage collection and other modern features for rapid development.<\/li>\n<\/ul>\n<p>I <em>have<\/em> found Go to be a good language to program a bot.\u00a0 The biggest downside was that the library ecosystem is a bit less mature than Python or C(++).\u00a0 That meant that getting the hardware driver layer of the bot together required quite some work:<\/p>\n<ul>\n<li>We found that the Go wrapper for OpenCV (<a href=\"https:\/\/github.com\/hybridgroup\/gocv#\">gocv<\/a>) required a <a href=\"https:\/\/github.com\/hybridgroup\/gocv\/compare\/master...fasaxc:master\">patch<\/a> to work on the Pi.\u00a0 (I found the patch in a forum post but I can&#8217;t dig it out to link to.)<\/li>\n<li>We didn&#8217;t find a working Go driver for the\u00a0VL53L0X time-of-flight sensors, so (after some false starts) we took the <a href=\"https:\/\/github.com\/cassou\/VL53L0X_rasp\">existing C-wrapper<\/a> that GitHub user <strong>cassou<\/strong> had already ported for the Pi and wrapped it in a <a href=\"https:\/\/github.com\/tigerbot-team\/tigerbot\/blob\/master\/go-controller\/pkg\/tofsensor\/tofsensor.go\">Go library<\/a> using CGo (Go&#8217;s C function call interface).<\/li>\n<li>We ported a Python sample joystick driver for the DS4\u00a0<a href=\"https:\/\/github.com\/tigerbot-team\/tigerbot\/blob\/master\/go-controller\/pkg\/joystick\/joystick.go\">to Go<\/a>.\u00a0 The Linux joystick interface turned out to be easy to access.<\/li>\n<li>There were a few i2c libraries without a clear winner.\u00a0 We ended up using\u00a0golang.org\/x\/exp\/io\/i2c.<\/li>\n<\/ul>\n<p>While it made some work, I find the low-level bit banging quite fun so it wasn&#8217;t much of a downside \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the past, we&#8217;ve used Python and C++ for our robots but this year we switched to Go.\u00a0 Why the change?\u00a0 It seemed like a good idea at the time To be honest, the main reason was that I signed up to lead the coding effort this year.\u00a0 I haven&#8217;t had much C++\/Qt experience (so &hellip; <a href=\"https:\/\/www.hardwarehacker.co.uk\/blog\/a-gopher-in-a-tiger\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">A Gopher in a Tiger?<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,5,11],"tags":[2],"_links":{"self":[{"href":"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-json\/wp\/v2\/posts\/218"}],"collection":[{"href":"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=218"}],"version-history":[{"count":2,"href":"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-json\/wp\/v2\/posts\/218\/revisions"}],"predecessor-version":[{"id":225,"href":"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-json\/wp\/v2\/posts\/218\/revisions\/225"}],"wp:attachment":[{"href":"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}