CoppeliaSim 4.3.0 User Manual - CoppeliaSim 4.3.0 使用者手冊

  • Home
    • Site Map
    • reveal
    • blog
  • welcome
  • userInterface
    • pagesAndViews
    • coordinateDialog
    • positionDialog
    • orientationDialog
    • objectMovement
    • positionOrientationTransformation
    • settings
    • shortcuts
  • scenesAndModels
    • scenes
    • models
    • modelDialog
  • environment
    • environmentPropertiesDialog
    • textureDialog
  • entities
    • collections
    • objects
      • sceneObjectPropertiesDialog
      • commonPropertiesDialog
    • collidableObjects
    • measurableObjects
    • detectableObjects
    • viewableObjects
    • convexHull
    • layerSelectionDialog
      • cameras
      • cameraPropertiesDialog
      • lights
      • lightPropertiesDialog
      • shapes
      • shapeReferenceFrames
      • primitiveShapes
      • convexDecomposition
      • shapeProperties
      • shapeDynamicsProperties
      • shapeDynamicEngineProperties
      • geometryDialog
      • shapeEditModes
      • triangleEditMode
      • vertexEditMode
      • edgeEditMode
      • groupedShapeEditMode
      • joints
      • jointModes
      • jointProperties
      • jointDynamicsProperties
      • jointDynamicEngineProperties
      • dummies
      • dummyPropertiesDialog
      • graphs
      • graphPropertiesDialog
      • proximitySensors
      • proximitySensorDescription
      • proximitySensorPropertiesDialog
      • proximitySensorVolumeDialog
      • proximitySensorDetectionParameterDialog
      • visionSensors
      • visionSensorDescription
      • visionSensorPropertiesDialog
      • forceSensors
      • forceSensorPropertiesDialog
      • octrees
      • octreePropertiesDialog
      • pointClouds
      • pointCloudPropertiesDialog
    • paths
  • functionality
    • geometricCalculations
    • collisionDetection
    • distanceCalculation
      • geometricPlugin
      • simGeom API
      • coppeliaGeometricRoutines
      • CoppeliaGeometricRoutinesAPI
    • IGLPluginAPIreference
    • kinematics
    • basicsOnIkGroupsAndIkElements
    • solvingIkAndFk
      • kinematicsPlugin
      • simIKAPI
      • coppeliaKinematicsRoutines
      • CoppeliaKinematicsRoutinesAPI
    • dynamicsModule
    • designingDynamicSimulations
      • dynamicsDialog
      • dynamicsEngineDialog
    • dataVisualizationAndOutput
    • externalFrontEnd
    • dataTransformation
    • meansOfCommunication
      • remoteApiOverview
      • zmqRemoteApiOverview
      • wsRemoteApiOverview
      • rosInterfaces
      • rosInterf
      • ROSPluginAPIreference
      • ros2Interface
      • ROS2PluginAPIreference
    • ZMQPluginAPIreference
    • WSPluginAPIreference
    • pathsAndTrajectories
    • pathAndMotionPlanningModules
    • OMPLPluginAPIreference
    • syntheticVision
    • IMPluginAPIreference
    • simVisionAPI
    • customUIPlugin
    • UIPluginAPIreference
    • simUI-widgets
    • QMLPluginAPIreference
    • importExport
    • xmlFormat
      • urdfPlugin
      • APIFunctions
      • sdfPlugin
      • SDFPluginAPIreference
    • aviRecorder
    • AssimpPluginAPIreference
    • GLTFPluginAPIreference
      • commandLine
      • LuaCmdPluginAPIreference
      • miscellaneousFunctionality
      • SurfRecPluginAPIreference
      • ICPPluginAPIreference
      • SubprocessPluginAPIreference
  • writingCode
    • scripts
      • embeddedScripts
      • simulationScripts
      • mainScript
      • childScripts
      • customizationScripts
      • scriptProperties
      • scriptEditor
    • addOns
    • sandboxScript
    • scriptExecution
    • threadedAndNonThreadedCode
      • callbackFunctions
      • dynCallbackFunctions
      • jointCallbackFunctions
      • contactCallbackFunction
      • visionCallbackFunctions
      • triggerCallbackFunctions
      • userConfigCallbackFunctions
    • luaPythonDifferences
    • luaCrashCourse
    • plugins
    • mainClientApplication
    • accessingSceneObjects
    • explicitHandling
    • apisOverview
      • apiFunctions
      • apiConstants
      • objectParameterIDs
  • simulation
    • simulationPropertiesDialog
  • tutorials
    • bubbleRobTutorial
    • buildingAModelTutorial
    • lineFollowingBubbleRobTutorial
    • inverseKinematicsTutorial
    • externalControllerTutorial
    • pluginTutorial
    • robotLanguageIntegrationTutorial
    • rosTutorial
      • ros1Tutorial
      • ros2Tutorial
    • compilingCoppeliaSim
triggerCallbackFunctions << Previous Next >> luaPythonDifferences

userConfigCallbackFunctions

User config callback functions

A customization script that includes a user config callback function (which is one of many system callback functions), will display a configuration dialog icon, in the scene hierarchy:

[Configuration dialog icon]


When double-cliked, the user config callback function is triggered. This can be used as a convenient way of displaying a custom user interface to the user, that is specific to the object/model the customization script is attached to. User data can be read and written to objects with sim.readCustomDataBlock/sim.writeCustomDataBlock for instance:

[Custom configuration dialog]


function sysCall_init()
    modelHandle=sim.getObject('.')
end

function sysCall_userConfig()
    local xml =[[<ui title="Robot" closeable="true" modal="true" layout="form" on-close="customUiClosed">
            <label text="Max. velocity:" />
            <edit id="1" value="-" on-editing-finished="velocityChanged"/>
            <label text="Max. acceleration:" />
            <edit id="2" value="-" on-editing-finished="accelerationChanged"/>
    </ui>]]
    local ui=simUI.create(xml)
    local data=readData()
    simUI.setEditValue(ui,1,tostring(data.maxVel))
    simUI.setEditValue(ui,2,tostring(data.maxAccel))
end

function customUiClosed(ui)
    simUI.destroy(ui)
end

function velocityChanged(ui,id,val)
    local data=readData()
    val=tonumber(val)
    if val then
        if val<0.1 then
            val=0.1
        end
        if val>0.5 then
            val=0.5 
        end
        data.maxVel=val
    end
    simUI.setEditValue(ui,id,tostring(data.maxVel))
    writeData(data)
end

function accelerationChanged(ui,id,val)
    local data=readData()
    val=tonumber(val)
    if val then
        if val<0.01 then
            val=0.01
        end
        if val>0.2 then
            val=0.2 
        end
        data.maxAccel=val
    end
    simUI.setEditValue(ui,id,tostring(data.maxAccel))
    writeData(data)
end

function readData()
    local data=sim.readCustomDataBlock(modelHandle,'RobotParams')
    if data then
        data=sim.unpackTable(data)
    else
        data={}
        data.maxVel=0.2
        data.maxAccel=0.05
    end
    return data
end

function writeData(data)
    sim.writeCustomDataBlock(modelHandle,'RobotParams',sim.packTable(data))
end

You may also use the configUI module for quicker set-up of custom configuration dialog, that will also automatically write data to custom data blocks:

[Custom configuration dialog based on configUI module]


require 'configUi'

function sysCall_init()
    local schema={
        floatInput={
            default=0.1,
            maximum=4,
            minimum=0.05,
            name="float input",
            type="float",
            ui={
                control="spinbox",
                tab="Tab 1",order=1,col=1
            },
        },
        intInput={
            default=1,
            maximum=10,
            minimum=0,
            name="int input",
            type="int",
            ui={
                control="spinbox",
                tab="Tab 1",order=2,col=2
            },
        },
        checkbox1={
            type='bool',
            name='checkbox1',
            default=true,
            ui={tab="Tab 1",order=3,col=1},
        },
        checkbox2={
            type='bool',
            name='checkbox2',
            default=false,
            ui={tab="Tab 1",order=4,col=2},
        },
        colorselect={
            type='color',
            name='color select',
            default={1,0,1},
            ui={tab="Tab 2",order=5,col=1,},
        },
        stringInput={
            default="Hello",
            name="string input",
            type="string",
            ui={
                tab="Tab 2",order=6,col=2
            },
        },
        floatSlider={
            default=0.5,
            maximum=1,
            minimum=0,
            name="float slider",
            type="float",
            ui={
                control="slider",
                tab="Tab 2",order=7,col=1
            },
        },
        intSlider={
            default=1,
            maximum=10,
            minimum=0,
            name="int slider",
            type="int",
            ui={
                control="slider",
                tab="Tab 2",order=8,col=2
            },
        },
        choices1={
            default=2,
            choices={"option 1","option 2","option 3"},
            name="combo choices",
            type="choices",
            ui={
                control="combo",
                tab="Tab 3",order=9,col=1
            },
        },
        choices2={
            default=1,
            choices={"option 1","option 2","option 3"},
            name="radio choices",
            type="choices",
            ui={
                control="radio",
                tab="Tab 3",order=10,col=1
            },
        },
    }
    sim.writeCustomDataBlock(sim.getObject('.'),'__schema__',sim.packTable(schema))
    configUi=ConfigUI('myModelType',nil,modificationCallback)
end

function modificationCallback(config)
    local objectHandle=sim.getObject('.')
    local txt="Object '"..sim.getObjectAlias(objectHandle,5).."' just changed.\nNew parameters are:"
    print(txt)
    print(config)
end



triggerCallbackFunctions << Previous Next >> luaPythonDifferences

Copyright © All rights reserved | This template is made with by Colorlib