Skip to content

4.12 BasScript Program Class

Overview

BasScript lets you construct BAS instruction sequences for the robot in a structured way from the host PC, covering motion, logic, program calls, communication, vision, and Modbus commands.

Core Features

  • Support for building motion instructions (MoveJoint, MoveLine, MoveCircle, etc.)
  • Support for building logic instructions (If, While, Switch, Goto, etc.)
  • Support for building assignment, wait, pause, and abort instructions
  • Support for building program call and management instructions
  • Support for building Socket communication instructions
  • Support for building Modbus register read/write instructions
  • Support for building vision program instructions
  • Support for setting extra parameters (acceleration, RTCP, frame offset, etc.)
  • Support for quick motion instructions (JUMP series)

Use Cases

  • Automatically generate complex robot programs
  • Edit and modify robot programs
  • Reuse common program modules and instruction sequences
  • Achieve seamless integration between host PC and robot programs
  • Build customized robot motion trajectories
  • Integrate vision, communication, and Modbus functions into robot programs

Constructor

Method NameBasScript( name : str) -> BasScript
DescriptionConstruct BAS instruction sequences for the robot
Request Parametersname : Script name
Compatible Robot Software VersionsCollaborative (Copper): v7.5.2.0+
Industrial (Bronze): v7.6.0.0+
NotesAll methods under this class have the same compatibility requirements as this class

Subclass Structure

BasScript class contains the following subclasses to organize different types of instructions:

  1. ExtraParam: Extra parameter class for building complex robot control commands
  2. BasMotion: Motion instruction subclass containing all robot motion-related methods
  3. BasLogical: Logic instruction subclass containing all logic control-related methods
  4. BasStructure: Structure instruction subclass containing all structure control-related methods
  5. BasSocket: Socket communication subclass containing all Socket communication-related methods
  6. BasModbus: Modbus communication subclass containing all Modbus communication-related methods
  7. BasVision: Vision instruction subclass containing all vision-related methods

4.12.1 ExtraParam

Method NameExtraParam() -> ExtraParam
DescriptionExtra parameter class for building complex robot control commands
Request ParametersNone
Return ValueExtraParam object

4.12.1.1 Set Acceleration

Method Nameextra_param.acceleration( value : float) -> None
DescriptionSet acceleration, range is 1~120%
Request Parametersvalue : float Acceleration value, unit: % (float)
Return ValueNone

4.12.1.2 Set RTCP Parameter

Method Nameextra_param.rtcp() -> None
DescriptionSet RTCP parameter, only supports MoveL and MoveC instructions
Request ParametersNone
Return ValueNone

4.12.1.3 Set Frame Offset

Method Nameextra_param.offset( index : int) -> None
DescriptionSet frame offset
Request Parametersindex : int Offset index (integer)
Return ValueNone

4.12.1.4 Set Time-Based Operation or Assignment

Method Nameextra_param.tb( second : int, type : str, name : str = None, index : int = None, status : str = None) -> None
DescriptionSet time-based operation or assignment, range is 0.01-30s, values less than 0.01 will not be saved successfully
Request Parameterssecond : int Seconds, unit: sec (integer)
type : str Execution type (string)
name : str Name (for operation, string)
index : int Index (for assignment, integer)
status : str Status (for assignment, string)
Return ValueNone

4.12.1.5 Set Jump

Method Nameextra_param.skip( index : int) -> None
DescriptionSet jump, when the jump condition set by the SKIP CONDITION instruction is met, jump directly from the current line containing the SKIP instruction to the target instruction line or target program
Request Parametersindex : int Index of the target label (integer)
Return ValueNone

4.12.1.6 Set Departure Distance and Approaching Distance

Method Nameextra_param.approach( departure_dist : float, approaching_dist : float) -> None
DescriptionSet departure distance and approaching distance for door-type motion, only used for JUMP instructions
Request Parametersdeparture_dist : float Departure distance, unit: mm (float)
approaching_dist : float Approaching distance, unit: mm (float)
Return ValueNone

4.12.2 BasMotion

4.12.2.1 MoveJoint Motion to Point Instruction

Method Namemotion.move_joint( pose_type : MovePoseType, pose_index : int, speed_type : SpeedType, speed_value : float, smooth_type : SmoothType, smooth_distance : float = 0.0, extra_param : ExtraParam = None) -> StatusCodeEnum
DescriptionJoint motion instruction, moves the robot to a specified position in the workspace with the specified movement speed and method
Request Parameterspose_type : MovePoseType Pose type
pose_index : int Pose index
speed_type : SpeedType Speed type
speed_value : float Speed value, unit: %
smooth_type : SmoothType Smooth type
smooth_distance : float Smooth distance, unit: mm, range: 0~1000
extra_param : ExtraParam Additional parameters
Return ValueStatusCodeEnum: Function execution result

4.12.2.2 MoveLine Linear Motion to Point Instruction

Method Namemotion.move_line( pose_type : MovePoseType, pose_index : int, speed_type : SpeedType, speed_value : float, smooth_type : SmoothType, smooth_distance : float = 0.0, extra_param : ExtraParam = None) -> StatusCodeEnum
DescriptionLinear motion instruction, moves the robot in a straight line to a specified position in the workspace with the specified movement speed and method
Request Parameterspose_type : MovePoseType Pose type
pose_index : int Pose index
speed_type : SpeedType Speed type
speed_value : float Speed value, unit: mm/s
smooth_type : SmoothType Smooth type
smooth_distance : float Smooth distance, unit: mm, range: 0~1000
extra_param : ExtraParam Additional parameters
Return ValueStatusCodeEnum: Function execution result

4.12.2.3 MoveCircle Arc Motion to Point Instruction

Method Namemotion.move_circle( pose_type1 : MovePoseType, pose_index1 : int, pose_type2 : MovePoseType, pose_index2 : int, speed_type : SpeedType, speed_value : float, smooth_type : SmoothType, smooth_distance : float = 0.0, extra_param : ExtraParam = None) -> StatusCodeEnum
DescriptionArc motion instruction, moves the robot in an arc to a specified position in the workspace with the specified movement speed and method
Request Parameterspose_type1 : MovePoseType First pose type
pose_index1 : int First pose index
pose_type2 : MovePoseType Second pose type
pose_index2 : int Second pose index
speed_type : SpeedType Speed type
speed_value : float Speed value, unit: mm/s
smooth_type : SmoothType Smooth type
smooth_distance : float Smooth distance, unit: mm, range: 0~1000
extra_param : ExtraParam Additional parameters
Return ValueStatusCodeEnum: Function execution result

4.12.2.4 JUMP Quick Motion Instruction

Method Namemotion.move_jump( pose_type : MovePoseType, pose_index : int, speed_value : float, speed_ratio : float, lim_Z_type : SpeedType, lim_Z_value : float, smooth_type : SmoothType, smooth_distance : float = 0.0, extra_param : ExtraParam = None) -> StatusCodeEnum
DescriptionDoor-type motion instruction, specifies the robot to perform door-type motion (first vertical ascent, then horizontal movement, finally vertical descent)
Request Parameterspose_type : MovePoseType Target pose storage type
pose_index : int Index of the target position
speed_value : float Movement speed value, unit: mm/s
speed_ratio : float Movement speed ratio, unit: %
lim_Z_type : SpeedType Z-axis limit type
lim_Z_value : float Z-axis limit value
smooth_type : SmoothType Smooth type
smooth_distance : float Smooth distance, unit: mm, range: 0~1000
extra_param : ExtraParam Additional parameters
Return ValueStatusCodeEnum: Function execution result

4.12.2.5 JUMP3 Quick Motion Instruction

Method Namemotion.move_jump3( pose_type : MovePoseType, pose_index : List[int], speed_value : float, speed_ratio : float, smooth_type : SmoothType, smooth_distance : float = 0.0, extra_param : ExtraParam = None) -> StatusCodeEnum
DescriptionDoor-type motion instruction, specifies the robot to perform door-type motion with three positions: departure, approach, and target
Request Parameterspose_type : MovePoseType Target pose storage type
pose_index : List[int] List of 3 target position indices (departure, approach, target)
speed_value : float Movement speed value, unit: mm/s
speed_ratio : float Movement speed ratio, unit: %
smooth_type : SmoothType Smooth type
smooth_distance : float Smooth distance, unit: mm, range: 0~1000
extra_param : ExtraParam Additional parameters
Return ValueStatusCodeEnum: Function execution result

4.12.2.6 JUMP3CP Quick Motion Instruction

Method Namemotion.move_jump3cp( pose_type : MovePoseType, pose_index : List[int], speed_value : float, smooth_type : SmoothType, smooth_distance : float = 0.0, extra_param : ExtraParam = None) -> StatusCodeEnum
DescriptionDoor-type motion instruction, specifies the robot to perform door-type motion with three positions: departure, approach, and target
Request Parameterspose_type : MovePoseType Target pose storage type
pose_index : List[int] List of 3 target position indices (departure, approach, target)
speed_value : float Movement speed value, unit: mm/s
smooth_type : SmoothType Smooth type
smooth_distance : float Smooth distance, unit: mm, range: 0~1000
extra_param : ExtraParam Additional parameters
Return ValueStatusCodeEnum: Function execution result

4.12.3 BasLogical

4.12.3.1 LogiIf Conditional Instruction

Method Namelogical.logi_if( param1 : Union[RegisterType, IOType], index : int, param2 : Union[RegisterType, IOType, OtherType], value : Union[int, float, str, IOStatus], operator : BooleanOperator = BooleanOperator.EQ) -> StatusCodeEnum
DescriptionConditional judgment instruction, executes different code blocks according to the specified condition
Request Parametersparam1 : Union[RegisterType, IOType] First parameter (register or IO signal)
index : int Index of parameter 1
param2 : Union[RegisterType, IOType, OtherType] Second parameter (register, IO signal, or other type)
value : Union[int, float, str, IOStatus] Index or value of parameter 2
operator : BooleanOperator Logical operator
Return ValueStatusCodeEnum: Function execution result

4.12.3.2 LogiElseIf Conditional Branch Instruction

Method Namelogical.logi_else_if( param1 : Union[RegisterType, IOType], index : int, param2 : Union[RegisterType, IOType, OtherType], value : Union[int, float, str, IOStatus], operator : BooleanOperator = BooleanOperator.EQ) -> StatusCodeEnum
DescriptionConditional branch instruction, judges whether the ElseIf condition is met when the If condition is not met
Request Parametersparam1 : Union[RegisterType, IOType] First parameter (register or IO signal)
index : int Index of parameter 1
param2 : Union[ValueType, IOType, OtherType] Second parameter (register, IO signal, or other type)
value : Union[int, float, IOStatus] Index or value of parameter 2
operator : BooleanOperator Logical operator
Return ValueStatusCodeEnum: Function execution result

4.12.3.3 LogiElse Else Instruction

Method Namelogical.logi_else() -> StatusCodeEnum
DescriptionElse instruction, executes when all If and ElseIf conditions are not met
Request ParametersNone
Return ValueStatusCodeEnum: Function execution result

4.12.3.4 LogiEndIf End Conditional Instruction

Method Namelogical.logi_end_if() -> StatusCodeEnum
DescriptionEnd conditional instruction, used to end the If condition statement block
Request ParametersNone
Return ValueStatusCodeEnum: Function execution result

4.12.3.5 LogiWhile Loop Instruction

Method Namelogical.logi_while( param1 : Union[RegisterType, IOType], index : int, param2 : Union[RegisterType, IOType, OtherType], value : Union[int, float, str, IOStatus], operator : BooleanOperator = BooleanOperator.EQ) -> StatusCodeEnum
DescriptionLoop instruction, repeatedly executes the code in the loop body when the condition is met
Request Parametersparam1 : Union[RegisterType, IOType] First parameter (register or IO signal)
index : int Index of parameter 1
param2 : Union[RegisterType, IOType, OtherType] Second parameter (register, IO signal, or other type)
value : Union[int, float, str, IOStatus] Index or value of parameter 2
operator : BooleanOperator Logical operator
Return ValueStatusCodeEnum: Function execution result

4.12.3.6 LogiEndWhile End Loop Instruction

Method Namelogical.logi_end_while() -> StatusCodeEnum
DescriptionEnd loop instruction, used to end the While loop statement block
Request ParametersNone
Return ValueStatusCodeEnum: Function execution result

4.12.3.7 LogiSwitch Multi-branch Selection Instruction

Method Namelogical.logi_switch( param : Union[RegisterType, IOType], index : int) -> StatusCodeEnum
DescriptionMulti-branch selection instruction, selects different branches to execute according to the value of the expression, supports BREAK statement to exit the branch
Request Parametersparam : Union[RegisterType, IOType] Register or IO signal
index : int Index number
Return ValueStatusCodeEnum: Function execution result

4.12.3.8 LogiCase Branch Instruction

Method Namelogical.logi_case( param : Union[RegisterType, IOType, OtherType], value : Union[int, float, str]) -> StatusCodeEnum
DescriptionBranch instruction, used to define branch conditions in Switch statements
Request Parametersparam : Union[RegisterType, IOType, OtherType] Register, IO signal, or other type
value : Union[int, float, str] Index number or value
Return ValueStatusCodeEnum: Function execution result

4.12.3.9 LogiDefault Default Branch Instruction

Method Namelogical.logi_default() -> StatusCodeEnum
DescriptionDefault branch instruction, executes when all Case conditions are not met
Request ParametersNone
Return ValueStatusCodeEnum: Function execution result

4.12.3.10 LogiEndSwitch End Multi-branch Selection Instruction

Method Namelogical.logi_end_switch() -> StatusCodeEnum
DescriptionEnd multi-branch selection instruction, used to end the Switch statement block
Request ParametersNone
Return ValueStatusCodeEnum: Function execution result

4.12.3.11 LogiGoto Jump Instruction

Method Namelogical.logi_goto( index : int) -> StatusCodeEnum
DescriptionJump instruction, used to jump the program to a specified label position within the same program and continue executing from that position; must insert the LABEL instruction first, then use the GOTO instruction
Request Parametersindex : int Index of the target label
Return ValueStatusCodeEnum: Function execution result

4.12.3.12 LogiLabel Label Instruction

Method Namelogical.logi_label( index : int) -> StatusCodeEnum
DescriptionLabel instruction, used to define jump target positions in the program, GOTO instructions can jump to this label position
Request Parametersindex : int Label index
Return ValueStatusCodeEnum: Function execution result

4.12.3.13 LogiSkipCondition Skip Condition Instruction

Method Namelogical.logi_skip_condition( param1 : Union[RegisterType, IOType], index : int, param2 : Union[RegisterType, IOType, OtherType], value : Union[int, float, str, IOStatus], operator : BooleanOperator = BooleanOperator.EQ) -> StatusCodeEnum
DescriptionSkip condition instruction, used to set jump conditions, when the condition is met, jump directly from the current line containing the SKIP instruction to the target instruction line or target program
Request Parametersparam1 : Union[RegisterType, IOType] First parameter (register or IO signal)
index : int Index of parameter 1
param2 : Union[RegisterType, IOType, OtherType] Second parameter (register, IO signal, or other type)
value : Union[int, float, str, IOStatus] Index or value of parameter 2
operator : BooleanOperator Logical operator
Return ValueStatusCodeEnum: Function execution result

4.12.3.14 LogiBreak Break Loop Instruction

Method Namelogical.logi_break() -> StatusCodeEnum
DescriptionBreak loop instruction, used to exit the current loop or Switch statement
Request ParametersNone
Return ValueStatusCodeEnum: Function execution result

4.12.3.15 LogiContinue Skip Loop Instruction

Method Namelogical.logi_continue() -> StatusCodeEnum
DescriptionSkip loop instruction, used to skip the remaining part of the current loop and enter the next loop
Request ParametersNone
Return ValueStatusCodeEnum: Function execution result

4.12.4 BasStructure

4.12.4.1 Wait Wait Condition Instruction

Method Namestructure.wait( param1 : Union[RegisterType, IOType], index : int, param2 : Union[ValueType, IOType, OtherType], value : Union[int, float, IOStatus], operator : BooleanOperator = BooleanOperator.EQ) -> StatusCodeEnum
DescriptionWait condition instruction, executes the WAIT instruction only when the condition is met, otherwise waits until the condition is met
Request Parametersparam1 : Union[RegisterType, IOType] First parameter (register or IO signal)
index : int Index of parameter 1
param2 : Union[ValueType, IOType, OtherType] Second parameter (register, IO signal, or other type)
value : Union[int, float, IOStatus] Index or value of parameter 2
operator : BooleanOperator Logical operator
Return ValueStatusCodeEnum: Function execution result

4.12.4.2 WaitTime Wait Time Instruction

Method Namestructure.wait_time( param : ValueType, value : Union[int, float]) -> StatusCodeEnum
DescriptionWait time instruction, executes the WAIT TIME instruction, the robot waits for the specified time before continuing to execute subsequent instructions
Request Parametersparam : ValueType Parameter type (R register or value)
value : Union[int, float] Time value, unit: sec
Return ValueStatusCodeEnum: Function execution result

4.12.4.3 Pause Pause Instruction

Method Namestructure.pause() -> StatusCodeEnum
DescriptionPause instruction, when executing to the Pause instruction, pauses the program execution, the robot immediately plans a deceleration trajectory and stops, the program enters the pause state. To continue execution, you need to press the start button again
Request ParametersNone
Return ValueStatusCodeEnum: Function execution result

4.12.4.4 Abort Abort Instruction

Method Namestructure.abort() -> StatusCodeEnum
DescriptionForce end instruction: Ends program execution, the robot servo immediately brakes, the brake is applied, and the servo bus is powered off. After executing the force end instruction, the program enters the terminated state, and the cursor stops at the current line
Request ParametersNone
Return ValueStatusCodeEnum: Function execution result

4.12.4.5 Call Synchronous Program Call Instruction

Method Namestructure.call( name : str) -> StatusCodeEnum
DescriptionSynchronous program call instruction, calls the specified program and waits for its execution to complete before continuing to execute the current program, supports calling preset BAS programs
Request Parametersname : str Program name
Return ValueStatusCodeEnum: Function execution result

4.12.4.6 Run Asynchronous Program Call Instruction

Method Namestructure.run( name : str) -> StatusCodeEnum
DescriptionAsynchronous program call instruction, calls the specified program and returns immediately, continuing to execute the current program, supports calling preset BAS programs
Request Parametersname : str Program name
Return ValueStatusCodeEnum: Function execution result

4.12.4.7 Load Load Program Instruction

Method Namestructure.load( name : str) -> StatusCodeEnum
DescriptionLoad program instruction, loads the specified program into memory
Request Parametersname : str Program name
Return ValueStatusCodeEnum: Function execution result

4.12.4.8 Unload Unload Program Instruction

Method Namestructure.unload( name : str) -> StatusCodeEnum
DescriptionUnload program instruction, unloads the specified program from memory
Request Parametersname : str Program name
Return ValueStatusCodeEnum: Function execution result

4.12.4.9 Exec Execute Program Instruction

Method Namestructure.exec( name : str) -> StatusCodeEnum
DescriptionExecute program instruction, executes the specified program
Request Parametersname : str Program name
Return ValueStatusCodeEnum: Function execution result

4.12.5 BasSocket

4.12.5.1 SocketOpen Open Socket Connection Instruction

Method Namesocket.socket_open( index : int) -> StatusCodeEnum
DescriptionUse Socket Open instruction to create a Server and wait for Client connection
Request Parametersindex : int SK register sequence number
Return ValueStatusCodeEnum: Function execution result

4.12.5.2 SocketClose Close Socket Connection Instruction

Method Namesocket.socket_close( index : int) -> StatusCodeEnum
DescriptionClose the specified socket connection
Request Parametersindex : int SK register sequence number
Return ValueStatusCodeEnum: Function execution result

4.12.5.3 SocketConnect Connect Socket Instruction

Method Namesocket.socket_connect( index : int) -> StatusCodeEnum
DescriptionUse Socket Connect instruction to connect to the specified socket server
Request Parametersindex : int SK register sequence number
Return ValueStatusCodeEnum: Function execution result

4.12.5.4 SocketSend Send Socket Data Instruction

Method Namesocket.socket_send( index : int, msg_type : StrType, value : Union[int, str]) -> StatusCodeEnum
DescriptionUse Socket Send instruction to send data to the specified socket connection
Request Parametersindex : int SK register sequence number
msg_type : StrType Message type
value : Union[int, str] Message content or sequence number
Return ValueStatusCodeEnum: Function execution result

4.12.5.5 SocketRecv Receive Socket Data Instruction

Method Namesocket.socket_recv( index : int, msg_lenth : int, msg_type : StrType, value : Union[int, str]) -> StatusCodeEnum
DescriptionUse Socket Recv instruction to read characters from the specified socket connection, can specify maximum length
Request Parametersindex : int SK register sequence number
msg_lenth : int Maximum message length
msg_type : StrType Message type
value : Union[int, str] Message content or sequence number
Return ValueStatusCodeEnum: Function execution result

4.12.6 BasModbus

4.12.6.1 ModbusReadMH Read Modbus Holding Register Instruction

Method Namemodbus.modbus_read_MH( index : int, id : int, address : int, length : int, r_index : int) -> StatusCodeEnum
DescriptionRead Modbus holding register instruction
Request Parametersindex : int Channel sequence number
id : int Modbus ID
address : int Register starting address
length : int Register length, i.e., the number of registers to read
r_index : int R register starting sequence number for writing results
Return ValueStatusCodeEnum: Function execution result

4.12.6.2 ModbusReadMI Read Modbus Input Register Instruction

Method Namemodbus.modbus_read_MI( index : int, id : int, address : int, length : int, r_index : int) -> StatusCodeEnum
DescriptionRead Modbus input register instruction
Request Parametersindex : int Channel sequence number
id : int Modbus ID
address : int Register starting address
length : int Register length, i.e., the number of registers to read
r_index : int R register starting sequence number for writing results
Return ValueStatusCodeEnum: Function execution result

4.12.6.3 ModbusWriteMH Write Modbus Holding Register Instruction

Method Namemodbus.modbus_write_MH( index : int, id : int, address : int, length : int, value_type : ValueType, value : int) -> StatusCodeEnum
DescriptionWrite Modbus holding register instruction
Request Parametersindex : int Channel sequence number
id : int Modbus ID
address : int Register starting address
length : int Register length, i.e., the number of registers to write
value_type : ValueType Value type
value : int Value or R register starting index
Return ValueStatusCodeEnum: Function execution result

4.12.7 BasVision

4.12.7.1 VisionFind Find Vision Program Instruction

Method Namevision.vision_find( name : str) -> StatusCodeEnum
DescriptionExecute vision find program
Request Parametersname : str Vision program name
Return ValueStatusCodeEnum: Function execution result

4.12.7.2 VisionGetOffset Get Vision Program Offset Instruction

Method Namevision.vision_get_offset( name : str, index : int, label_index : int) -> StatusCodeEnum
DescriptionGet the offset after executing the vision program
Request Parametersname : str Vision program name
index : int Vision register index
label_index : int Label index
Return ValueStatusCodeEnum: Function execution result

4.12.7.3 VisionGetQuantity Get Vision Program Result Instruction

Method Namevision.vision_get_quantity( name : str, index : int) -> StatusCodeEnum
DescriptionGet the result quantity after executing the vision program
Request Parametersname : str Vision program name
index : int R register index for storing results
Return ValueStatusCodeEnum: Function execution result

4.12.8 Direct Methods

4.12.8.1 SetParam Set Parameter Instruction

Method Namebas_script.set_param( type : ParamType, value_type : ValueType, value : Union[int, float]) -> StatusCodeEnum
DescriptionSet parameter instruction, used to set various parameters of the robot
Request Parameterstype : ParamType Parameter type
value_type : ValueType Value type
value : Union[int, float] Value
Return ValueStatusCodeEnum: Function execution result

4.12.8.2 AssignValue Assignment Instruction

Method Namebas_script.assign_value( param1 : AssignType, index : int, param2 : Union[AssignType, OtherType], value : Union[int, float, str, IOStatus, CurrentPose], opt_index : int = 0, opt_value = 0) -> StatusCodeEnum
DescriptionAssignment instruction, used to assign values to registers, IO signals, etc.
Request Parametersparam1 : AssignType First parameter (register or IO signal)
index : int Index of parameter 1
param2 : Union[AssignType, OtherType] Second parameter (register, IO signal, or other type)
value : Union[int, float, str, IOStatus, CurrentPose] Index or value of parameter 2
opt_index : int Additional index when parameter 1 is PR_ELEMENT
opt_value : int Additional index when parameter 2 is PR_ELEMENT or pulse value when value is IOStatus.PULSE
Return ValueStatusCodeEnum: Function execution result