NAOqi:将NAO代码从2.1迁移至2.8时DCM替代方案咨询
Great question! NAOqi 2.8 officially retired the DCM module, and its functionality has been split across core modules like ALMotion (for alias management and actuator control) and ALFrameManager (for process cycle callbacks). Let's walk through rewriting your code step by step:
Replacing DCM Alias Operations
The DCM's alias creation and value setting functionality is now fully handled by the ALMotion module. The method names are nearly identical, so you only need to swap out the proxy type:
// Replace DCMProxy with ALMotionProxy AL::ALMotionProxy motionProxy(pBroker); // Create alias (same parameter format as DCM's createAlias) motionProxy.createAlias(someAliasDeclaration); // Set values for the alias (matches DCM's setAlias behavior) motionProxy.setAlias(someValuesForAlias);
Replacing Pre/Post Process Callbacks
The atPreProcess and atPostProcess hooks from DCM are replaced by callback registration in ALFrameManager, which manages the robot's processing cycle. Here's how to register your functions:
// Get the ALFrameManager proxy AL::ALFrameManagerProxy frameManager(pBroker); // Register pre-process callback (equivalent to atPreProcess) frameManager.registerPreProcessCallback("MyCustomPreCallback", &someFunction); // Register post-process callback (equivalent to atPostProcess) frameManager.registerPostProcessCallback("MyCustomPostCallback", &someOtherFunction);
If you need to unregister these callbacks later (e.g., when your module shuts down), use:
frameManager.unregisterPreProcessCallback("MyCustomPreCallback"); frameManager.unregisterPostProcessCallback("MyCustomPostCallback");
Full Modified Code Example
Putting it all together, your updated code will look like this:
// Initialize motion and frame manager proxies AL::ALMotionProxy motionProxy(pBroker); AL::ALFrameManagerProxy frameManager(pBroker); // Handle alias creation and configuration motionProxy.createAlias(someAliasDeclaration); motionProxy.setAlias(someValuesForAlias); // Register cycle callbacks frameManager.registerPreProcessCallback("CustomPreProcess", &someFunction); frameManager.registerPostProcessCallback("CustomPostProcess", &someOtherFunction);
Key Notes
- Alias Compatibility: The alias declaration format used with DCM works exactly the same with
ALMotion::createAlias, so you don't need to modify your existing alias definitions. - Callback Signatures: Ensure your callback functions have a
void()signature (no parameters) to matchALFrameManager's requirements. - Low-Level Control: If you were using DCM for direct hardware access,
ALMotionprovides equivalent low-level methods likesetAngles,getAngles, andsetTorquesthat are fully supported in NAOqi 2.8+.
内容的提问来源于stack exchange,提问作者Thomas

