Kinovarobotics / kortex

Code examples and API documentation for KINOVA® KORTEX™ robotic arms
https://www.kinovarobotics.com/
Other
107 stars 84 forks source link

Control Mode Notification #152

Open jabbershort opened 1 year ago

jabbershort commented 1 year ago

Description

The ControlConfig.OnNotificationControlModeTopic isn't publishing anything when control mode is changed. Also only provides high level information. Is there any other way to fetch how the arm is being controlled. My target is to be able to visualise the Xbox controller mode (i.e. cartesian, orientation or angular control and which joint is being controlled).

Version

At a minimum, provide the Kortex API and Kortex-enabled device versions.

KortexAPI : 2.5.0

Kortex Device : Gen3

Steps to reproduce

Based on the Notification example script edited as:

Code example

import sys
import os
import time
import threading

from kortex_api.autogen.client_stubs.DeviceConfigClientRpc import DeviceConfigClient
from kortex_api.autogen.client_stubs.BaseClientRpc import BaseClient
from kortex_api.autogen.client_stubs.ControlConfigClientRpc import ControlConfigClient

from kortex_api.autogen.messages import DeviceConfig_pb2, Session_pb2, Base_pb2, ControlConfig_pb2

from kortex_api.Exceptions.KException import KException
from google.protobuf import json_format

def example_notification(base: BaseClient,config: ControlConfigClient):

    def notification_callback(data):
        print("****************************")
        print("* Callback function called *")
        print(json_format.MessageToJson(data))
        print("****************************")

    handle = Base_pb2.ControllerHandle()
    handle.controller_identifier = 1

    # Subscribe to ConfigurationChange notifications
    print("Subscribing to ConfigurationChange notifications")
    notif_options = ControlConfig_pb2.NotificationOptions()
    notif_handle = config.OnNotificationControlModeTopic(notification_callback,Base_pb2.NotificationOptions())

    def callback():
        config.Unsubscribe(notif_handle)

    timer = threading.Timer(60,callback)
    timer.start()
def main():
    # Import the utilities helper module
    sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
    import utilities

    # Parse arguments
    args = utilities.parseConnectionArguments()

    # Create connection to the device and get the router
    with utilities.DeviceConnection.createTcpConnection(args) as router:

        # Create required services
        base = BaseClient(router)
        config  = ControlConfigClient(router)

        # Example core
        example_notification(base,config)

if __name__ == "__main__":
    main()

Expected behavior

The Control Mode should be published to log.