Skip to content

[RSDK-13623] Implement golang bindings into the trajex CAPI#15

Merged
acmorrow merged 4 commits into
viam-modules:mainfrom
acmorrow:RSDK-13623-trajex-go-wrapper
May 26, 2026
Merged

[RSDK-13623] Implement golang bindings into the trajex CAPI#15
acmorrow merged 4 commits into
viam-modules:mainfrom
acmorrow:RSDK-13623-trajex-go-wrapper

Conversation

@acmorrow
Copy link
Copy Markdown
Collaborator

Ignore the cgo build stuff, it is obviously local to my system. Otherwise, this is a potential shape of things. The whole stack works, the tests pass (on my machine).

@acmorrow acmorrow requested review from JohnN193 and npmenard May 21, 2026 22:20
Copy link
Copy Markdown
Contributor

@JohnN193 JohnN193 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

certainly easier to follow than cartographer. few small things but lgtm past that.

claude also had some nits, but they didn't seem that useful (like using Description to describe optionals & defaults)

Comment thread go/totg/rdk/service.go
@@ -0,0 +1,215 @@
//go:build !windows && !no_cgo
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alittle weird calling the directory go, as that will make all the imports point to trajex/go, since things will import as go.<XXX> unless its manually changed.

mostly a nit, but maybe something like trajex/pkg/trajex would work instead? that way it still imports to trajex.<xxx>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, claude and I went around a few times before settling on this. There is prior art for this. Basically, if we don't have go.mod at the root of the tree then it makes import naming weird for consumers. If we do have go.mod at the root of the tree, we can rename away from go and then it just becomes canonically the go tree. I had wanted to put the go sources under src/viam the same way the C++ sources are, but due to golang's pedantic insistence, that would have put src into the package name. Yuck. Overall, this seemed cleanest.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah having peeps rename is fine with me

Comment thread go/totg/totg.go
if err := ctx.Err(); err != nil {
return err
}
inHandle := (*C.viam_trajex_tensor_map_t)(inputs.UnsafeHandle())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check against nil inputs?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that useful / idiomatic in go? I sort of feel like passing nil in for an object pointer means you get a panic makes sense. Happy to be told otherwise since this isn't my language.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the past we ran into issues with nils getting passed around in go, (some relevant tickets https://viam.atlassian.net/browse/RSDK-7743 and https://viam.atlassian.net/browse/RSDK-6070)

tbh I don't expect it to happen with trajex, but with rdk we would lean to being more defensive to avoid panics

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, easy to add.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I looked a little deeper, and the C side will error this for us, no changes required here.

Comment thread go.mod Outdated
@@ -0,0 +1,201 @@
module github.com/viamrobotics/trajex
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless we plan on swapping to viamrobotics for this repo, we prob want to change this

Suggested change
module github.com/viamrobotics/trajex
module github.com/viam-modules/trajex

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good catch. I missed that claude got the repo wrong because I'm workign against a local replacement.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah its not something that would have shown up till later

@acmorrow acmorrow requested a review from JohnN193 May 26, 2026 18:21
@acmorrow
Copy link
Copy Markdown
Collaborator Author

@JohnN193 - I pushed a meaningful change not based on your review. It restructures how we pick up the CAPI library dependency by making a new internal/capi library to anchor it. It makes the whole thing a little cleaner because now there is one and only one place that needs the C API library on the link line in the cgo metadata.

@acmorrow acmorrow merged commit d073aaf into viam-modules:main May 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants