Package: rocs-client
RoCS Python Client SDKThe SDK operates based on the concept of encapsulation, neatly organizing essential robot functions into separate classes, each equipped with specialized methods. Developers can make use of these encapsulated capabilities through provided interfaces, making it easy to create customized applications seamlessly. Whether you need to fine-tune low-level motor operations, coordinate complex high-level motion sequences, manage audio/video transmission, implement SLAM for mapping, or monitor odometry, the SDK's modular structure ensures flexibility and simplicity for developers to customize your solutions.Note: We presume that you have already installed and configured bothPythonandpipcorrectly. If not, please consult the appropriate resources for guidance on their installation. The recommended Python versions are 3.8 and above.Installing Python Client SDKThe RoCS Client Python packages can be easily installed or upgraded from PyPI with the following command.pipinstallrocs_clientVerifying the InstallationRun the following command to verify the installation:Windows Users:python-mpiplist|findstrrocs-clientLinux Users:python-mpiplist|greprocs-clientThe following output signifies a successful installation.C:\Users\Fourier>python-mpiplist|findstrrocs-client
rocs-client1.3.3Using Python Client SDKImport the SDK to your Python code.importrocs_client# Import the RoCS Client moduleCreate a humanoid robot object.fromrocs_clientimportHuman# Import Human class, which represents behaviors of a humanoid robot.human=Human(host='192.168.12.1')# Replace the IP with actual IP of your device.Note: RoCS supports three types of robots: dog, car and human. The above statement creates an instance of theHumanclass and assigns it to the variablehuman.  TheHumanclass includes functionalities related to communication and interaction with the GR humanoid robot at the specified IP address.Control the robot.You can use the following methods of thehumanclass to control the robot:_control_svr_start(): turns on the robot._control_svr_status(): checks the current operational status of the robot._control_svr_log_view(): checks logs related to the robot's operations. It provides insights into the robot's runtime activities and events._control_svr_close(): initiates the process of shutting down the robot.stop(): triggers an emergency stop (halts with power off).exit(): ends robot control session.stand(): commands the robot to stand in place.walk(angle, speed): guides the robot in movement.angle(float): controls direction with a range of plus or minus 45 degrees. Positive for left, negative for right. The value is an 8-digit floating-point number.speed(float): manages forward and backward movement with a range of plus or minus 0.8. Positive for forward, negative for backward. The value is an 8-digit floating-point number.head(roll, pitch, yaw):  directs the GR robot's head movements.roll(float): controls the roll angle (rotation around the x-axis). Negative for left, positive for right, within the range of (-17.1887-17.1887).pitch(float): adjusts the pitch angle (rotation around the y-axis). Positive for nodding forward, negative for nodding backward, within the range of (-17.1887-17.1887).yaw(float): manages the yaw angle (rotation around the z-axis). Negative for turning left, positive for turning right, within the range of (-17.1887-17.1887).move_joint(*motor): moves joints (variable length parameter, capable of controlling multiple joints simultaneously, estimated delay 2ms).motor(Motor): joint object, provides joint mapping relationships and parameter numbers throughhuman.motor_limits.upper_body(arm_action, hand_action): executes preset commands for the upper limbs.arm_action(ArmAction): enumeration for arm preset commands.hand_action(HandAction): enumeration for hand preset commands.Example CodesFollowing are example code snippets showcasing the utilization of the Python Client SDK for robot control:Code for Controlling Whole Robot (rocs_client>=1.0)Note: The version of the RoCS Client should be version 1.0 or higher for this example. Run commandpip show rocs_clientin a terminal to check the version of the installed package.importtimefromrocs_clientimportHumanfromrocs_client.robot.humanimportArmAction,HandAction# Connect to your robot using its IP addresshuman=Human(host='192.168.9.17')# Replace '192.168.9.17' with your robot's actual IP# Activate remote control for the robothuman.start()# Wait for 10 seconds to ensure the robot's control system stabilizes after initiating the remote control command start().time.sleep(10)# Instruct the robot to stand uphuman.stand()# Move the robot forward at a speed of 0.1human.walk(0,0.1)# Gesture: Wave the left handhuman.upper_body(arm=ArmAction.LEFT_ARM_WAVE)# Gesture: Wave both handshuman.upper_body(arm=ArmAction.TWO_ARMS_WAVE)# Gesture: Tremble the fingershuman.upper_body(hand=HandAction.TREMBLE)Code for Controlling Motors (rocs_client>=1.3.3)importmathimportthreadingimporttimeimportunittestfromrocs_clientimportMotormotor=Motor(host="192.168.137.210")arm_motor=motor.limits[0:17]iflen(motor.limits)>18else[]clamping_jaw=motor.limits[17:19]iflen(motor.limits)>20else[]dexterous_hand=motor.limits[19:31]iflen(motor.limits)>32else[]print(f'arm_motor:{arm_motor}')print(f'clamping_jaw:{clamping_jaw}')print(f'dexterous_hand:{dexterous_hand}')motors=arm_motor+clamping_jawdefset_pds_flag():""" Enable the switch/flag for setting pd parameters """foriteminmotors:motor.set_motor_pd_flag(item['no'],item['orientation'])motor.exit()defset_pds():""" Set pd parameters """foriteminmotors:motor.set_motor_pd(item['no'],item['orientation'],0.36,0.042)motor.exit()defsmooth_motion_by_interpolation(no,orientation,target_angle,offset=0.05,interval=0.004):"""Use differential to move the motor smoothlyArgs:no: Number of the motor to be operatedorientation: Orientation of the motor to be operatedtarget_angle: Angle of motionoffset: The Angle of each moveinterval: Interval of differential"""ifint(no)>8:print('Motor number greater than 8 is not supported.')returndefwait_target_done(rel_tol=2):whileTrue:try:p=motor.get_motor_pvc(no,orientation)['data']['position']ifmath.isclose(p,target_angle,rel_tol=rel_tol):breakexceptExceptionase:print(f'wait_target_done err:{e}')whileTrue:try:result=motor.get_motor_pvc(no,orientation)current_position=result['data']['position']ifcurrent_positionisnotNone:breakexceptExceptionase:print(f'current_position err:{e}')target_position=target_anglecycle=abs(int((target_position-current_position)/offset))foriinrange(0,cycle):iftarget_position>current_position:current_position+=offsetelse:current_position-=offsetmotor.move_motor(no,orientation,current_position)time.sleep(interval)wait_target_done()defenable_all():""" Enable All Motors """foriteminmotors:motor.enable_motor(item['no'],item['orientation'])time.sleep(1)defdisable_all(offset=1,interval=0.015):"""Disable All Motors """def_disable_left():foriinrange((len(motors)-1),-1,-1):item=motors[i]ifitem['orientation']=='left':smooth_motion_by_interpolation(item['no'],item['orientation'],0,offset,interval)foriinrange((len(motors)-1),-1,-1):item=motors[i]ifitem['orientation']=='left':motor.disable_motor(item['no'],item['orientation'])def_disable_right():foriinrange((len(motors)-1),-1,-1):item=motors[i]ifitem['orientation']!='left':smooth_motion_by_interpolation(item['no'],item['orientation'],0,offset=1.5,interval=0.02)foriinrange((len(motors)-1),-1,-1):item=motors[i]ifitem['orientation']!='left':motor.disable_motor(item['no'],item['orientation'])time.sleep(2)t_left=threading.Thread(target=_disable_left)t_right=threading.Thread(target=_disable_right)t_left.start(),t_right.start()t_left.join(),t_right.join()motor.exit()classTestHumanMotor(unittest.TestCase):deftest_set_pd_flag(self):""" Enable the switch/flag for setting pd parameters """set_pds_flag()deftest_set_pd(self):""" Set pd parameters """set_pds()deftest_enable_motors(self):""" Enable All Motors """enable_all()deftest_disable_motors(self):""" Disable All Motors """disable_all()deftest_get_pvc(self):""" Obtain the specified motor information """print(f"test_get_pvc{motor.get_motor_pvc('0','yaw')}")motor.exit()deftest_action_sample(self):"""This is a sample actionWhen initially controlling a motor individually, it is strongly recommended to run this function for testing.If the motor moves smoothly and predictably, explore slightly more complex actions.However, if the motor becomes unresponsive or behaves unexpectedly, fine-tune the P and D parameters.If the robotic arm's movements are smooth and stable, build more advanced programming on this foundation.To coordinate multiple joints for simultaneous motion, consider using the `threading` approach for control.Additional examples provide specific details."""enable_all()smooth_motion_by_interpolation('2','left',-20)smooth_motion_by_interpolation('3','left',-40)# disable_all()Code for Controlling Hands (rocs_client>=1.3.3)fromrocs_clientimportMotormotor=Motor(host="192.168.12.1")deftest_enable_hand():"""Enabling hand"""motor.enable_hand()motor.exit()deftest_disable_hand():""" Disabled hand """motor.disable_hand()motor.exit()deftest_get_hand_position():""" Obtain Hand Position"""print(f'test_get_hand_position:{motor.get_hand_position()}')test_enable_hand()angle=500motor.move_motor('11','left',angle)motor.move_motor('12','left',angle)motor.move_motor('13','left',angle)motor.move_motor('14','left',angle)motor.move_motor('11','right',angle)motor.move_motor('12','right',angle)motor.move_motor('13','right',angle)motor.move_motor('14','right',angle)motor.exit()Code for End Effector Controlling (rocs_client>=1.3.4)importthreadingimporttimefromrocs_clientimportEndEffector,EndEffectorScheme# Creating an instance of the EndEffectorend_effector=EndEffector(host="127.0.0.1")# Enable the end control serviceend_effector.enable()time.sleep(5)defleft():end_effector.control_left(EndEffectorScheme(x=1,y=1,z=1,qx=1,qy=1,qz=1,qw=1))defright():end_effector.control_right(EndEffectorScheme(x=1,y=1,z=1,qx=1,qy=1,qz=1,qw=1))t_left=threading.Thread(target=left)t_right=threading.Thread(target=right)t_right.start()t_right.start()Additional Test CasesAdditional test cases can be found inTest Cases.Release HistoryVersionReleased ByDateNew Feature0.1Fourier Software Department2023.81. Project initiation2. Confirm basic architecture0.2Fourier Software Department2023.91. Control module, system module2. Specific coding1.1Fourier Software Department2023.101. Hand, head preset actions2. Single joint control of upper body1.2Fourier Software Department2023.11Smooth movement example for single motor control1.3Fourier Software Department2023.12Individual control of dexterous hand