This repository was archived by the owner on Jun 2, 2025. It is now read-only.
Replies: 2 comments
-
Hello, package main
import (
"github.com/aler9/goroslib"
"github.com/aler9/goroslib/pkg/msg"
)
// define a custom service.
// unlike the standard library, a .srv file is not needed.
type AddTwoIntsReq struct {
A int64
B int64
}
type AddTwoIntsRes struct {
Sum int64
}
type AddTwoInts struct {
msg.Package `ros:"my_package"`
AddTwoIntsReq
AddTwoIntsRes
}
func onService(req *AddTwoIntsReq) (*AddTwoIntsRes, bool) {
return &AddTwoIntsRes{
Sum: req.A + req.B,
}, true
}
func main() {
// create a node and connect to the master
n, err := goroslib.NewNode(goroslib.NodeConf{
Name: "goroslib_sp",
MasterAddress: "127.0.0.1:11311",
})
if err != nil {
panic(err)
}
defer n.Close()
// create a service provider
sp, err := goroslib.NewServiceProvider(goroslib.ServiceProviderConf{
Node: n,
Name: "add_two_ints",
Srv: &AddTwoInts{},
Callback: onService,
})
if err != nil {
panic(err)
}
defer sp.Close()
// freeze main loop
select {}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
@aler9 good |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
@aler9 hello
The call function of the service called by the client written in C returns boolean type. If I use goroslib to provide a service to retrieve the database and return a record, if no record is found, the call function of the C client will be blocked.
Beta Was this translation helpful? Give feedback.
All reactions