Browse Source

Added an exclusive block.

Currently only supports ex2, but more can be added similar to andN.

Modified dt.ctrl to use the ex2 block to prevent simultanious activation of
focusbox outputs.

Made and block calculate functions status to prevent conflicts.
jeroen
Jeroen Vreeken 5 years ago
parent
commit
c76e67c71b
5 changed files with 161 additions and 8 deletions
  1. +4
    -4
      controller/block/block_and.c
  2. +113
    -0
      controller/block/block_ex.c
  3. +34
    -0
      controller/block/block_ex.test.ctrl
  4. +3
    -0
      controller/block/build.mk
  5. +7
    -4
      controller/dt_ctrl.ctrl

+ 4
- 4
controller/block/block_and.c View File

@ -43,28 +43,28 @@ struct controller_block_private {
bool *i[0];
};
void calculate_2(struct controller_block *block)
static void calculate_2(struct controller_block *block)
{
struct controller_block_private *priv = block->private;
priv->q = *priv->i[0] & *priv->i[1];
}
void calculate_3(struct controller_block *block)
static void calculate_3(struct controller_block *block)
{
struct controller_block_private *priv = block->private;
priv->q = *priv->i[0] & *priv->i[1] & *priv->i[2];
}
void calculate_4(struct controller_block *block)
static void calculate_4(struct controller_block *block)
{
struct controller_block_private *priv = block->private;
priv->q = *priv->i[0] & *priv->i[1] & *priv->i[2] & *priv->i[3];
}
void calculate_5(struct controller_block *block)
static void calculate_5(struct controller_block *block)
{
struct controller_block_private *priv = block->private;


+ 113
- 0
controller/block/block_ex.c View File

@ -0,0 +1,113 @@
/*
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2015
Copyright Stichting C.A. Muller Radioastronomiestation, 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 <controller/controller_block.h>
#include <log/log.h>
/*
inputs outputs
nr name nr name
----------------------
| |
---| 0 a 0 q |----
| |
---| 1 b |
| |
----------------------
*/
struct io {
bool q;
bool *i;
};
struct controller_block_private {
struct io io[0];
};
static void calculate_2(struct controller_block *block)
{
struct controller_block_private *priv = block->private;
priv->io[0].q = *priv->io[0].i & !(*priv->io[1].i);
priv->io[1].q = *priv->io[1].i & !(*priv->io[0].i);
}
static struct controller_block_interm_list interms_2[] = {
{ "a", CONTROLLER_BLOCK_TERM_BOOL, offsetof(struct controller_block_private, io[0].i) },
{ "b", CONTROLLER_BLOCK_TERM_BOOL, offsetof(struct controller_block_private, io[1].i) },
{ NULL }
};
static struct controller_block_outterm_list outterms_2[] = {
{ "qa", CONTROLLER_BLOCK_TERM_BOOL, offsetof(struct controller_block_private, io[0].q) },
{ "qb", CONTROLLER_BLOCK_TERM_BOOL, offsetof(struct controller_block_private, io[1].q) },
{ NULL }
};
static struct controller_block * block_ex(struct controller_block *block)
{
if (controller_block_add(block))
goto err_block;
return block;
err_block:
controller_block_free(block);
return NULL;
}
static struct controller_block *block_err(struct controller_block *block)
{
controller_block_free(block);
return NULL;
}
static struct controller_block * block_ex2_create(char *name, int argc, va_list val)
{
struct controller_block *block;
if (!(block = controller_block_alloc("ex2", name, sizeof(struct controller_block_private) + sizeof(bool *) * 2)))
return NULL;
if (controller_block_interm_list_init(block, interms_2))
return block_err(block);
if (controller_block_outterm_list_init(block, outterms_2))
return block_err(block);
block->calculate = calculate_2;
return block_ex(block);
}
BLOCK_CREATE(ex2) = {
.create = block_ex2_create,
.args = { NULL },
};

+ 34
- 0
controller/block/block_ex.test.ctrl View File

@ -0,0 +1,34 @@
trigger {
{ "immediate" }
}
blocks (100.0, 0.0) {
{ "ex2", "ex2" }
{ "test_input_bool", "test_input_a" }
{ "test_input_bool", "test_input_b" }
{ "test_output_bool", "test_output_qa" }
{ "test_output_bool", "test_output_qb" }
}
links {
{ "test_input_a", "value", "ex2", "a", true }
{ "test_input_b", "value", "ex2", "b", true }
{ "ex2", "qa", "test_output_qa", "value", true }
{ "ex2", "qb", "test_output_qb", "value", true }
}
params {
{ "test_input_a", "value", 4,
(int) { false, true, false, true } }
{ "test_input_b", "value", 4,
(int) { false, false, true, true } }
{ "test_output_qa", "value", 4,
(int) { false, true, false, false } }
{ "test_output_qb", "value", 4,
(int) { false, false, true, false } }
}
set trace_server false

+ 3
- 0
controller/block/build.mk View File

@ -14,6 +14,7 @@ BLOCKS := \
counter \
debug \
decoder_uint32_bool \
ex \
filter_iir \
filter_lp \
friction \
@ -66,6 +67,7 @@ BLOCKS_NO_C := \
and3 \
and4 \
and5 \
ex2 \
value_float
ifneq ($(OS), FreeBSD)
@ -102,6 +104,7 @@ CTRL_TESTS += \
$(DIR)/block_command_bool.test.output \
$(DIR)/block_command_float.test.output \
$(DIR)/block_command_uint32.test.output \
$(DIR)/block_ex.test.output \
$(DIR)/block_gain.test.output \
$(DIR)/block_gain_ratio_abs.test.output \
$(DIR)/block_i2t.test.output \


+ 7
- 4
controller/dt_ctrl.ctrl View File

@ -107,8 +107,9 @@ blocks ($(frequency), $(delay)) {
{ "log", "elevation_torsion_range_log" }
{ "log", "elevation_position_safe_log" }
{ "command_bool", "focusbox_plus" }
{ "command_bool", "focusbox_min" }
{ "command_bool", "focusbox_plus" }
{ "command_bool", "focusbox_min" }
{ "ex2", "focusbox_exclusive" }
{ "value_bool", "false" }
{ "value_float", "zero" }
@ -221,8 +222,10 @@ links {
{ "elevation_torque_l", "value", "dt_el_l", "torque" , true }
{ "elevation_servo_state", "enable", "dt_el_r", "enable" , true }
{ "elevation_servo_state", "enable", "dt_el_l", "enable" , true }
{ "focusbox_plus", "value", "dt_el_r", "ba1" , true }
{ "focusbox_min", "value", "dt_el_r", "ba2" , true }
{ "focusbox_plus", "value", "focusbox_exclusive", "a" , true }
{ "focusbox_min", "value", "focusbox_exclusive", "b" , true }
{ "focusbox_exclusive", "qa", "dt_el_r", "ba1" , true }
{ "focusbox_exclusive", "qb", "dt_el_r", "ba2" , true }
{ "false", "value", "dt_el_l", "ba1" , true }
{ "false", "value", "dt_el_l", "ba2" , true }


Loading…
Cancel
Save