Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help With Object Provider and Composition Provider #2281

Open
rivermoon21 opened this issue Jan 31, 2019 · 6 comments
Open

Help With Object Provider and Composition Provider #2281

rivermoon21 opened this issue Jan 31, 2019 · 6 comments

Comments

@rivermoon21
Copy link

Hello, I am trying to build and display an object that has a root folder, subsystems, and the subsystem's data point. However, when I try in the code, the subsystems appear repeatedly every time [as shown in pic].
objectproviderinfinite

Can you guys help me figure out what I need to add to my Object Provider or Composition provider? I thought it would display it by adding the 'telemetry' argument

here is my json file (similar to tutorial found online):

 {
        "name": "Spacecraft",
        "type": 'folder',
        "namespace": "public.namespace",
        "key": "sc",
        "subsystems": [
             {
                 "name": "Propulsion",
                 "key": "prop",
                 "namespace": "public.namespace",
                 "measurements": [
                     {
                         "name": "Fuel",
                         "key": "prop.fuel",
                         "units": "kilograms",
                         "type": "float",
                     },
                     {
                         "name": "Thrusters",
                         "key": "prop.thrusters",
                         "units": "None",
                         "type": "string",
                     }
                 ]
             },
             {
                 "name": "Communications",
                 "key": "comms",
                 "namespace": "public.namespace",
                 "measurements": [
                     {
                         "name": "Received",
                         "key": "comms.recd",
                         "units": "bytes",
                         "type": "integer",
                     },
                     {
                         "name": "Sent",
                         "key": "comms.sent",
                         "units": "bytes",
                         "type": "integer",
                     }
                 ]
             },
             {
                 "name": "Power",
                 "key": "pwr",
                 "namespace": "public.namespace",
                 "measurements": [
                     {
                         "name": "Generator Temperature",
                         "key": "pwr.temp",
                         "units": "\u0080C",
                         "type": "float",
                     },
                     {
                         "name": "Generator Current",
                         "key": "pwr.c",
                         "units": "A",
                         "type": "float",
                     },
                     {
                         "name": "Generator Voltage",
                         "key": "pwr.v",
                         "units": "V",
                         "type": "float",
                     }
                 ]
             }
        ]
     }

And Object Provider:

        openmct.objects.addProvider('public.namespace', {
            get: function (identifier) {
                 return objectPromise.then(function(data) {
                    if(identifier.key === 'my-root-major-key')
                    {
                       return{
                          identifier: identifier,
                          name: data.name,
                          type: data.type,
                       }
                    }
                    else {
                       var measurement = data.subsystems.filter(function (m) {
                             return m.key === identifier.key;
                       })[0];
                       // include subsystem name
                       if (!measurement.key.toString().includes('.')) {
                          return {
                             identifier: identifier,
                             name: measurement.name,
                             type: 'folder',
                             telemetry: {
                                 values: measurement.measurements,
                                 type: 'example.telemetry',
                                 key: ''
                             },
                             location: 'public.namespace:my-root-major-key:'
                          };
                       }
                    }
                 });
            }
        });

And Composition Provider:

        openmct.composition.addProvider({
            appliesTo: function (domainObject) {
               return domainObject.identifier.namespace === 'public.namespace' &&
                    domainObject.type === 'folder';
            },
            load: function (domainObject) {
                return objectPromise.then(function (data) {
                        return data.subsystems.map(function (m) {
                            return {
                                namespace: 'public.namespace',
                                key: m.key,
                            };
                        });
                    });
            }
        });

Issue: Help in displaying my objectn correctly with its subsystems and their respective telemetry.
Severirty: Trivial.

@andreasGBL
Copy link

It looks like the problem lies within your composition provider.
It applies to every domainObject which resides in the namespace public.namespace and is of type folder.
But all your subsytem domainObjects also reside in the namespace public.namespace and are of the type folder. So everytime a new object is added by the objectprovider openmct checks if the compositionprovider applies to it and load all the subsytem domainobjects for it too. And since all of your domainObjects apply to it it will end in an endless loop.
You can fix it tho by changing your appliesTo function, for example try:

appliesTo: function (domainObject) {
               return domainObject.identifier.namespace === 'public.namespace' &&
                    domainObject.type === 'folder' &&
                    domainObject.identifier.key === 'my-root-major-key';
            }

Also to answer your second question why they are not shown as telemetry types:

  1. First of all I hope you added your telemetry type to openmct.
  2. You assigned the type folder to every subsytem domainObject. Thats why its displayed as a folder.
  3. The telemetry field should only consist of the values array.

Try to use

return {
    identifier: identifier,
    name: measurement.name,
    type: 'example.telemetry',
    telemetry: {
        values: measurement.measurements,
    },
    location: 'public.namespace:my-root-major-key'
};                       

in your object provider.

Also your root key 'my-root-major-key' and the root key in the json file ('sc') don't match. That is not a problem, but it is definitely confusing.

@rivermoon21
Copy link
Author

Thanks for the help. That solved one of the issues I was facing. Now the hierarchy shows the spacecraft and the subsystems. However, it doesn't show the telemetry data point of each subsystem in the hierarchy tree on the left. It only shows it on the main screen (right). [as shown in the image]

propulsion

power

Do you have any suggestions for this?

It seems to be pretty close, I just don't see what changes I need to do.

This is what I have as far as types and providers:

` openmct.objects.addRoot({
namespace: 'public.namespace',
key: 'my-root-major-key'
});

       openmct.types.addType('example.my-type', {
         name: "My Personal Type",
         description: "This is a personal type that I added!",
         creatable: true,
         cssClass: "icon-plot-resource"
       });

       openmct.types.addType('example.telemetry', {
         name: "My Personal Type",
         description: "This is a personal type that I added!",
         cssClass: "icon-plot-resource"
       });

       openmct.types.addType('example.subsytem', {
         name: "My subsytem Type",
         description: "This is a subsytem type that I added!",
         cssClass: "icon-folder"
       });


       openmct.objects.addProvider('public.namespace', {
           get: function (identifier) {
                return objectPromise.then(function(data) {

                   if(identifier.key === 'my-root-major-key')
                   {
                      return{
                         identifier: identifier,
                         name: data.name,
                         type: data.type,
                         location: 'ROOT'
                      }
                   }
                   //fill in data points for each subsytem
                   else {
                      var measurement = data.subsystems.filter(function (m) {
                            return m.key === identifier.key;
                      })[0];

                      return {
                         identifier: identifier,
                         name: measurement.name,
                         type: 'example.subsytem',
                         telemetry: {
                             values: measurement.measurements,
                         },
                         location: 'public.namespace:my-root-major-key'
                      };
                   }
                });
           }
       });


       openmct.composition.addProvider({
         appliesTo: function (domainObject) {
            return domainObject.identifier.namespace === 'public.namespace' &&
                  domainObject.type === 'folder' &&
                  domainObject.identifier.key === 'my-root-major-key';
         },
         load: function (domainObject) {
            return objectPromise.then(function (data) {
              return data.subsystems.map(function (m) {
                 return {
                      namespace: 'public.namespace',
                      key: m.key
                 };
              });
           });
        }
    });`

@deeptailor
Copy link
Contributor

@MauriceRivers - You need to provide values for all measurement types. Please share your repo so I can fully understand the issue you are having

@rivermoon21
Copy link
Author

Here is the link to my repo:
https://github.com/mauricerivers/openmct-testing-objects/blob/master/index.html

All the code is in the index.html because I am just trying to get this to work. Then I will clean out the repo.
Hope you can help. Thanks.

@jakeaston
Copy link

Was there any solution to this?
I too am looking to produce a composition provider that supports Root-->Subsystem-->Telemetry object

@serbuh
Copy link

serbuh commented Feb 26, 2024

I published my solution to folder hierarchy here:
Discussion: Folders hierarchy #7494

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants