Beta8397 / virtual_robot

A 2D robot simulator to help beginners learn Java programming for FTC Robotics
100 stars 171 forks source link

Add support for remote fields... #49

Closed alan412 closed 3 years ago

alan412 commented 3 years ago

The remote field is only 8 feet by 12 feet. I haven't thought yet about what all needs to be changed, but it would be good to have the red and blue remote fields both in.

(I am in NC which has said all tournaments will be remote.)

alan412 commented 3 years ago

actually hold off a bit. I think I almost have it and if it works I'll give a pull request

jkenney2 commented 3 years ago

It would be best to have configuration options in the config file, e.g. full field, blue, or red, since teams that ordered a half field (as we did) already had to choose between blue and red.

The code that limits the robot's position to the field boundaries is located in each individual robot configuration class (for example ArmBot.java, which extends VirtualBot). But it is the same for each robot configuration, so I really should have made it a single method in the VirtualBot.java class to begin with, which then could be modified to behave differently for different field configurations. I think that's all that would be needed. Then could either use the whole field field graphic, or an altered square graphic with the unused part of the field made some different color.

jkenney2 commented 3 years ago

@alan412 The notion of a square field is baked into the VirtualBot class (base class for the various robot configuration classes), so that changing to a non-square rectangle resulted in some side effects. I changed FIELD_WIDTH to 435, and FIELD_WIDTH_INCHES to 96, and the field graphic to the remote version. This made the robot appear smaller (about 12 inches instead of 18). I couldn't drive down to the lower part of the field. For reasons I don't understand, it wasn't recognizing the red colors on the field. The distance sensors worked for some walls, but gave incorrect results for others. The programming board also got smaller. I started trying to make some changes in the VirtualBot class to accommodate a non-square field; I'm sure that's possible, but I wasn't getting very far.

So I tried this instead: see branch "constrain_field". It keeps a square field, but constrains the motion of the robot to a sub-rectangle that is specified in the Config class. Then I added some field graphics for red and blue remote fields; they are square, but the unused parts are replaced with dark gray. Seems to work ok.

jkenney2 commented 3 years ago

Just noticed though, the constrain_field branch introduces a distance sensor problem for whichever wall(s) has been constrained. Edit -- fixed distance sensor issue in constrain_field branch.

alan412 commented 3 years ago

constrain_field branch works for me. Might I suggest that the drawing uses CONFIG to gray out portions (instead of it being a different bmp). That feels pretty straightforward.

at some point during the season, I would like to root out all of the expectations that the field is square but that is a lot of effort now with the only benefit making me feel better. I think your approach is better for letting teams work now.

--Alan

jkenney2 commented 3 years ago

Made a few additional tweaks to constrain_field branch (including run-time masking rather than use of multiple images). Merged into master.