Kinovarobotics / Kinova-kortex2_Gen3_G3L

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

Control Mode Notification #152

Closed jabbershort closed 1 week 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.

martinleroux commented 1 month ago

Hi @jabbershort

The reason you are not seeing notifications is most likely that they do not trigger when you think they trigger. On Gen3, the control modes are Angular Joystick, Cartesian Joystick, Angular trajectory, Cartesian trajectory and Waypoint trajectory (you can see them in the dropdown menu of the Speed Limits Advanced tab).

If you use any of the joysticks, either from the Xbox controller or from the controls in the Web App, the robot will automatically change - you can see the notification for the control mode change by clicking the notification bell in the Web app.

From my understanding, you are trying to track the active mapping on the Xbox controller, which is done using the MappingInfoTopic (OnNotificationMappingInfoTopic()).

See here for reference: https://github.com/Kinovarobotics/ros_kortex/blob/noetic-devel/kortex_driver/protos/Base.proto#L203 https://github.com/Kinovarobotics/ros_kortex/blob/d57a287cdc85031ae351089b82c71cb8cace16be/kortex_driver/protos/Base.proto#L1073-L1080