I have code for a robot and want to simulate it, how do I put the code for the motors into Unreal accurately?
Way too little info here.
Human-robot? Mini robot? Axis?
You want to model the physical layout of the robot or motors in a modeling program (or a simple version in Unreal)
If it’s a complex robot you’ll need to build an animation rig.
The main issue is to make sure your commands to the robot motor use the same units for rotation. Is it sending commands for # of degrees to rotate a motor in a given length of time? Is it sending a command to rotate at x degrees per second for y seconds?
You can use Blueprints to start with.
its not too complex yet, and i know I need to make a rig, but its similar to this:
it sends commands to rotate at x degrees per second for y seconds. The lines of code for movement tend to look somewhat similar to this: “leftIntake.spin(forward,100,pct);” except for AI which is a ■■■■■ to code.
would I need to make a C++ library for this to translate the motor movements to simulated movements? im somewhat of a noob to unreal so
There’s a few things to keep in sync:
- You need to build the physical model of the robot. This needs to have appropriate joints defined for the axes of articulation in the robot (including “axles that wheels turn around.”) You can do this in the Unreal Blueprint editor, or you can do this in a tool like Maya or Blender, and import to Unreal. If you’re having trouble with this step, please ask in the art or animation forum.
- You need to configure the joints in question with the appropriate motor torques. This is a configuration step in the blueprint editor. Look for “join constraints” on the web, and read up on 1.5 - PhysicsConstraints | Unreal Engine Documentation
- You now need to apply the desired torques to these joints, based on your robot control output. This should be pretty straightforward – inside Tick(), figure out what the control input should be, and call the appropriate ApplyTorque function on each joint. The hardest part here is to get the coordinate systems right, and figuring out the conversion factor between the Unreal world units and your actual unit such as foot-pounds or newton-meters.
- Finally, you need to port the robot control loop. I’m assuming you already wrote this in C++ of some sort. You need to create a new C++ plugin for your project, and copy your robot control loop into that plugin. Then it’s probably easiest to make the control loop be started in its own thread by a blueprint library, which works fine as long as you only have one robot. If you need multiple robots, you will have to express the control loop in terms that an AIController will understand, which can take some surgery on the code to turn it “inside out” from your typical firmware control loop.
- Finally, the control loop needs to interface to the world – each time through your control loop, you sense some sensors, and you emit some output controls. Those are typically in terms of I2C/SPI bus transactions, UART reads/writes, and such – you will have to write alternatives for those operations that instead take input from the simulated world, and turn “send CAN bus command for joint 3” into data that you can use in step 3) to configure the joints inside Tick().
thank you im doing some work for an FPS and im trying to just grasp everything and I must admit, this is a difficult engine. currently on the weapon slots which I’ve been told I should make variables and it isn’t connecting for me. After I understand how to make an FPS in a decent manner, ill start working on this sim.