Navigation

core.math.lerp

Inputs

Name

Type

Title

Mandatory

Description

factor

core.type.f64

Factor

True

None

start

core.type.f64

Start value

True

None

end

core.type.f64

End value

True

None

Outputs

Name

Type

Title

Description

output

core.type.bool

Output

None

Parameters

Function has no parameters

State variables

Function has no state variables

Usage XML code snippet

core_math_lerp snippet for FLOW configuration file
<f name="lerp" by_spec="core.math.lerp">
    <in alias="factor">some_block_1/output</in>
    <in alias="start">some_block_2/output</in>
    <in alias="end">some_block_3/output</in>
</f>

Function’s artifacts

declaration.py
from fspeclib import *


Function(
    name='core.math.lerp',
    title=LocalizedString(
        en='Linear interpolation between two numbers'
    ),
    description=None,
    inputs=[
        Input(
            name='factor',
            title='Factor',
            value_type='core.type.f64'
        ),
        Input(
            name='start',
            title='Start value',
            value_type='core.type.f64'
        ),
        Input(
            name='end',
            title='End value',
            value_type='core.type.f64'
        )
    ],
    outputs=[
        Output(
            name='output',
            title='Output',
            value_type='core.type.bool'
        )
    ]
)
core_math_lerp_exec.c
#include "core_math_lerp.h"

void core_math_lerp_exec(
    const core_math_lerp_inputs_t *i,
    core_math_lerp_outputs_t *o
)
{
    if (i->start < i->end) {
        if (i->factor <= i->start) {
            o->output = i->start;
        } else if (i->factor >= i->end) {
            o->output = i->end;
        } else {
            o->output = i->start + (i->end - i->start) * i->factor;
        }
    } else {
        if (i->factor <= i->end) {
            o->output = i->end;
        } else if (i->factor >= i->start) {
            o->output = i->start;
        } else {
            o->output = i->start + (i->end - i->start) * i->factor;
        }
    }
}
core_math_lerp.h
/**
 *  Automatically-generated file. Do not edit!
 */

#ifndef FSPEC_CORE_MATH_LERP_H
#define FSPEC_CORE_MATH_LERP_H

#include <stdint.h>
#include <eswb/types.h>

#include "function.h"

/* Include declaration of dependency types */
#include "core_type_bool.h"
#include "core_type_f64.h"

/**
 * @brief Inputs of `core.math.lerp` function
 */
typedef struct core_math_lerp_inputs_ {
    core_type_f64_t factor;  /// Factor
    core_type_f64_t start;  /// Start value
    core_type_f64_t end;  /// End value

} core_math_lerp_inputs_t;

/**
 * @brief Outputs of `core.math.lerp` function
 */
typedef struct core_math_lerp_outputs_ {
    core_type_bool_t output; /// Output

} core_math_lerp_outputs_t;

typedef struct core_math_lerp_eswb_descriptors_ {
    eswb_topic_descr_t in_factor;
    eswb_topic_descr_t in_start;
    eswb_topic_descr_t in_end;
    eswb_topic_descr_t out_all;
} core_math_lerp_eswb_descriptors_t;

typedef struct core_math_lerp_interface_ {
    core_math_lerp_inputs_t i;
    core_math_lerp_outputs_t o;
    core_math_lerp_eswb_descriptors_t eswb_descriptors;
} core_math_lerp_interface_t;

void core_math_lerp_exec(const core_math_lerp_inputs_t *i, core_math_lerp_outputs_t *o);

#endif // FSPEC_CORE_MATH_LERP_H
core_math_lerp_spec.c
/**
 *  Automatically-generated file. Do not edit!
 */

#include "core_math_lerp.h"
#include <eswb/types.h>

static const param_spec_t *params[1] = {
    NULL
};

static const input_spec_t i_factor = {
    .name = "factor",
    .annotation = "Factor",
    .flags = 0
};

static const input_spec_t i_start = {
    .name = "start",
    .annotation = "Start value",
    .flags = 0
};

static const input_spec_t i_end = {
    .name = "end",
    .annotation = "End value",
    .flags = 0
};

static const input_spec_t *inputs[4] = {
    &i_factor,
    &i_start,
    &i_end,
    NULL
};

static const output_spec_t o_output = {
    .name = "output",
    .annotation = "Output",
    .flags = 0
};

static const output_spec_t *outputs[2] = {
    &o_output,
    NULL
};

fspec_rv_t core_math_lerp_call_init_inputs(void *dh, const func_conn_spec_t *conn_spec, eswb_topic_descr_t mounting_td);

fspec_rv_t core_math_lerp_call_init_outputs(
    void *dh,
    const func_conn_spec_t *conn_spec,
    eswb_topic_descr_t mounting_td,
    const char *func_name
);

void core_math_lerp_call_exec(void *dh);

const function_spec_t atomic_core_math_lerp_spec = {
    .name = "core.math.lerp",
    .annotation = "Linear interpolation between two numbers",
    .inputs = inputs,
    .outputs = outputs,
    .params = params
};

const function_calls_t atomic_core_math_lerp_calls = {
    .interface_handle_size = sizeof(core_math_lerp_interface_t),
    .init = NULL,
    .init_inputs = core_math_lerp_call_init_inputs,
    .init_outputs = core_math_lerp_call_init_outputs,
    .pre_exec_init = NULL,
    .exec = core_math_lerp_call_exec,
    .set_params = NULL
};

const function_handler_t atomic_core_math_lerp_handler = {
    .spec = &atomic_core_math_lerp_spec,
    .calls = &atomic_core_math_lerp_calls,
    .extension_handler = NULL
};
core_math_lerp_interface.c
/**
 *  Automatically-generated file. Do not edit!
 */

#include "core_math_lerp.h"

#include "error.h"
#include <eswb/api.h>
#include <eswb/topic_proclaiming_tree.h>
#include <eswb/errors.h>

int core_math_lerp_interface_inputs_init(
    core_math_lerp_interface_t *interface,
    const func_conn_spec_t *conn_spec,
    eswb_topic_descr_t mounting_td
)
{
    eswb_rv_t rv;
    int errcnt_no_topic = 0;
    int errcnt_no_input = 0;
    const char *topic_path_in_factor = fspec_find_path2connect(conn_spec,"factor");
    const char *topic_path_in_start = fspec_find_path2connect(conn_spec,"start");
    const char *topic_path_in_end = fspec_find_path2connect(conn_spec,"end");

    // Connecting mandatory input "factor"
    if (topic_path_in_factor != NULL) {
        rv = eswb_connect_nested(mounting_td, topic_path_in_factor, &interface->eswb_descriptors.in_factor);
        if(rv != eswb_e_ok) {
            error("failed connect input \"factor\" to topic \"%s\": %s", topic_path_in_factor, eswb_strerror(rv));
            errcnt_no_topic++;
        }
    } else {
        error("mandatory input \"factor\" is not speicifed");
        errcnt_no_input++;
    }

    // Connecting mandatory input "start"
    if (topic_path_in_start != NULL) {
        rv = eswb_connect_nested(mounting_td, topic_path_in_start, &interface->eswb_descriptors.in_start);
        if(rv != eswb_e_ok) {
            error("failed connect input \"start\" to topic \"%s\": %s", topic_path_in_start, eswb_strerror(rv));
            errcnt_no_topic++;
        }
    } else {
        error("mandatory input \"start\" is not speicifed");
        errcnt_no_input++;
    }

    // Connecting mandatory input "end"
    if (topic_path_in_end != NULL) {
        rv = eswb_connect_nested(mounting_td, topic_path_in_end, &interface->eswb_descriptors.in_end);
        if(rv != eswb_e_ok) {
            error("failed connect input \"end\" to topic \"%s\": %s", topic_path_in_end, eswb_strerror(rv));
            errcnt_no_topic++;
        }
    } else {
        error("mandatory input \"end\" is not speicifed");
        errcnt_no_input++;
    }

    if ((errcnt_no_input > 0) || (errcnt_no_topic > 0)) {
        if (errcnt_no_input > errcnt_no_topic) {
            return fspec_rv_no_input;
        } else {
            return fspec_rv_no_topic;
        }
    }
    return fspec_rv_ok;
}

fspec_rv_t core_math_lerp_interface_inputs_update(core_math_lerp_interface_t *interface)
{
    eswb_rv_t rv;

    rv = eswb_read(interface->eswb_descriptors.in_factor, &interface->i.factor);
    if(rv != eswb_e_ok) {
        /*FIXME nothing to do yet*/
    }

    rv = eswb_read(interface->eswb_descriptors.in_start, &interface->i.start);
    if(rv != eswb_e_ok) {
        /*FIXME nothing to do yet*/
    }

    rv = eswb_read(interface->eswb_descriptors.in_end, &interface->i.end);
    if(rv != eswb_e_ok) {
        /*FIXME nothing to do yet*/
    }

    return 0;
}

fspec_rv_t core_math_lerp_interface_outputs_init(
    core_math_lerp_interface_t *interface,
    const func_conn_spec_t *conn_spec,
    eswb_topic_descr_t mounting_td,
    const char *func_name
)
{
    TOPIC_TREE_CONTEXT_LOCAL_DEFINE(cntx, 2);
    core_math_lerp_outputs_t out;
    eswb_rv_t rv;

    topic_proclaiming_tree_t *rt = usr_topic_set_struct(cntx, out, func_name);

    usr_topic_add_struct_child(cntx, rt, core_math_lerp_outputs_t, output, "output", tt_int32);
    rv = eswb_proclaim_tree(mounting_td, rt, cntx->t_num, &interface->eswb_descriptors.out_all);
    if (rv != eswb_e_ok) {
        return fspec_rv_publish_err;
    }

    return fspec_rv_ok;
}

fspec_rv_t core_math_lerp_interface_outputs_update(core_math_lerp_interface_t *interface)
{
    eswb_rv_t rv;

    rv = eswb_update_topic(interface->eswb_descriptors.out_all, &interface->o);
    if (rv != eswb_e_ok) {
        return 1;
    }

    return 0;
}

void core_math_lerp_interface_update(core_math_lerp_interface_t *interface)
{
    core_math_lerp_interface_inputs_update(interface);
    core_math_lerp_exec(&interface->i, &interface->o);
    core_math_lerp_interface_outputs_update(interface);
}

fspec_rv_t core_math_lerp_call_init_inputs(void *dh, const func_conn_spec_t *conn_spec, eswb_topic_descr_t mounting_td)
{
    core_math_lerp_interface_t *interface = (core_math_lerp_interface_t*) dh;
    return core_math_lerp_interface_inputs_init(interface, conn_spec, mounting_td);
}

fspec_rv_t core_math_lerp_call_init_outputs(
    void *dh,
    const func_conn_spec_t *conn_spec,
    eswb_topic_descr_t mounting_td,
    const char *func_name
)
{
    core_math_lerp_interface_t *interface = (core_math_lerp_interface_t*) dh;
    return core_math_lerp_interface_outputs_init(interface, conn_spec, mounting_td, func_name);
}

void core_math_lerp_call_exec(void *dh)
{
    core_math_lerp_interface_t *interface = (core_math_lerp_interface_t*) dh;
    core_math_lerp_interface_update(interface);
}