steviet91 / furmulaone_source

Source repo for the car and track models
MIT License
0 stars 0 forks source link

Move config vars to class variables #23

Open steviet91 opened 4 years ago

steviet91 commented 4 years ago

Moving the config variables to class variables would help with asscessibility, e.g. drThrottlePedalMax can be access with Vehicle._drThrottlePedalMax by a separate file as opposed to having to import the config with the json module, thoughts @Thonners

Thonners commented 4 years ago

Can we not achieve both by having it set in (e.g. the vehicle) config file, but saved to a class variable during the initialisation of the Vehicle instance? Then we keep 'modifiable' files as json, so all .py files are left as is but the value is still accessible by other files if they have a vehicle instance. (Which on re-reading your question is I think what you meant anyway? If so, then yes!)

i.e. something along the lines of the following in the Vehicle initialisation: def init(...): .... self._drThrottlePedalMax = config['vehicle']['drThrottlePedalMax'] ...

steviet91 commented 4 years ago

Hmmmm....my thinking was.

class Lidar(object): _NRays = 3

This is callable as self._NRays within lidar, so we can overrite in a .json file or through a method call to change the instance. But we can call it elswhere as Lidar._NRays. Found this useful in my main script instead of having to declare a lidar object or go vehicle.lidar_front.NRays

Thonners commented 4 years ago

If it's never changed, then yeah can be set at that level, but it seems risky if it can be overwritten in the object instance... in that case it seems safer to keep/access it through the instance to ensure it's using the same value you are (presumably you're accessing it to calculate something?)