DeepBlueRobotics / DeepBlueSim

MIT License
8 stars 0 forks source link

Generalize functionality of controller's handling of WebSupervisor sim #59

Closed brettle closed 4 months ago

brettle commented 4 months ago

At the moment, the controller continuously reports self.position.{xyz} via the WebotsSupervisor sim device. This allows robot testing code to confirm the robot is where it is expected to be. I propose that this should be generalized as follows:

If a sim value with a name of the form {pose,velocity}[defPathOrId][index] is created on the WebotsSupervisor sim device, then after each subsequent sim timestep, but before the new simTime is reported, the controller will set the corresponding value via something like:

webotsSupervisorSim.set("{pose,velocity}[defPathOrId][index]", Objects.requireNonNullElse(robot.getFromDef(defPathOrId), robot.getFromId(Integer.parseInt(defPathOrId))).get{Pose,Velocity}()[index]);
brettle commented 4 months ago

If the above format is too inefficient, see wpilibsuite/allwpilib#6677.

brettle commented 4 months ago

@CoolSpy3, based on the reply to that issue, I'm going to bite the bullet and see how painful it would be to use NetworkTables for this. Let me know if you object.

CoolSpy3 commented 4 months ago

I'm not totally opposed to that. I'd be somewhat annoyed that sim communication can't be done fully through a single connection, so I might also suggest considering creating a subclass of SimDevice/SimDeviceSim that does basic array parsing (maybe just for ints, doubles, and/or booleans) using strings. If you do want to go with the NT route, DeepBlueSim/CommandVisualizerClient might have some useful example code. Scratch that, it looks like it doesn't have anything more useful than the WPILib docs.

brettle commented 4 months ago

I'm not totally opposed to that. I'd be somewhat annoyed that sim communication can't be done fully through a single connection, so I might also suggest considering creating a subclass of SimDevice/SimDeviceSim that does basic array parsing (maybe just for ints, doubles, and/or booleans) using strings.

Unfortunately there is no support for string values.

CoolSpy3 commented 4 months ago

Ah, yes, my bad. I'm too used to seeing the API as JSON.

brettle commented 4 months ago

It's looking like I'll be able to make it work. Fwiw, the size of DeepBlueSim.jar went from 1.6 MB to 21.4 MB.

brettle commented 4 months ago

Scratch that. 9.9 MB after removing camera server and opencv.

brettle commented 4 months ago

Fixed by PR #67.