Commit 0a25cc90 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Add command_float block (derived from command_bool).

A lot simpler than the 1d and 3d setpoint generator and perfect for
temperature settings ;)
Add test for command_float block.
parent f1dd655a
/*
Copyright Jeroen Vreeken (jeroen@vreken.net), 2015
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <log/log.h>
#include <controller/controller_block.h>
#include <controller/controller_command.h>
struct controller_block_private {
float value;
uint32_t id;
struct controller_command *command;
};
static void command_calculate(struct controller_block *cmd)
{
struct controller_block_private *priv = cmd->private;
struct command_entry c_entry;
if (!controller_command_queue_read(priv->command, &c_entry)) {
priv->value = c_entry.value.f;
priv->id = c_entry.id;
} else {
priv->id = COMMAND_ID_NONE;
}
}
static struct controller_block_outterm_list outterms[] = {
{ "value", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, value) },
{ "id", CONTROLLER_BLOCK_TERM_UINT32, offsetof(struct controller_block_private, id) },
{ NULL },
};
static struct controller_block * block_command_float_create(char *name, int argc, va_list val)
{
struct controller_block *cmd;
if (!(cmd = controller_block_alloc("command_float", name, sizeof(struct controller_block_private))))
return NULL;
cmd->private->value = false;
cmd->private->id = COMMAND_ID_NONE;
if (controller_block_outterm_list_init(cmd, outterms))
goto err_block;
cmd->calculate = command_calculate;
if (controller_block_add(cmd))
goto err_block;
cmd->private->command = controller_command_create(cmd, name, "Float");
cmd->private->command->value_type = COMMAND_VALUE_TYPE_FLOAT;
cmd->private->command->command_types[0] = COMMAND_PTYPE_SETPOINT;
return cmd;
err_block:
controller_block_free(cmd);
return NULL;
}
BLOCK_CREATE(command_float) = {
.create = block_command_float_create,
.args = { NULL },
};
trigger {
{ "immediate" }
}
blocks (10.0, 0.0) {
{ "command_float", "command_float" }
{ "test_output_float", "value" }
{ "test_output_uint32", "id" }
{ "test_command", "command" }
}
links {
{ "command_float", "value", "value", "value", true }
{ "command_float", "id", "id", "value", true }
}
set SETPOINT 4
set SPEED 5
set SETPOINT_TIME 6
set COMMAND_ID_NONE (int)0xffffffff
params {
{ "command", "command", "command_float", $[SETPOINT_TIME], 123, 1.0, 0, 500000000 }
{ "command", "command", "command_float", $[SETPOINT], 234, 2.0 }
{ "command", "command", "command_float", $[SETPOINT], 567, -1.0 }
{ "command", "command", "command_float", $[SETPOINT], 666, 0.0 }
{ "command", "command", "command_float", $[SETPOINT], 777, -10.0 }
{ "value", "value", 10,
(float) { 0.0, 1.0, 2.0, -1.0, 0.0, -10.0, -10.0, -10.0, -10.0, -10.0 },
(float) { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }
}
{ "id", "value", 10,
(int) { $[COMMAND_ID_NONE], 123, 234, 567, 666, 777, $[COMMAND_ID_NONE], $[COMMAND_ID_NONE], $[COMMAND_ID_NONE], $[COMMAND_ID_NONE] }
}
}
......@@ -7,6 +7,7 @@ BLOCKS := \
add \
bridge_pwm \
command_bool \
command_float \
counter \
debug \
decoder_uint32_bool \
......@@ -85,6 +86,7 @@ SRCS += $(BLOCK_SRCS)
CTRL_TESTS += \
$(DIR)/block_bridge_pwm.test.ctrl \
$(DIR)/block_command_bool.test.ctrl \
$(DIR)/block_command_float.test.ctrl \
$(DIR)/block_gain.test.ctrl \
$(DIR)/block_limit.test.ctrl \
$(DIR)/block_limit_var.test.ctrl \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment