fix everything
This commit is contained in:
parent
e8f246cfa5
commit
675efff85c
8 changed files with 71 additions and 41 deletions
|
|
@ -2,6 +2,7 @@ SRCS = \
|
||||||
src/controller.c \
|
src/controller.c \
|
||||||
src/pid.c \
|
src/pid.c \
|
||||||
src/sc_rxc.c \
|
src/sc_rxc.c \
|
||||||
|
src/sc_rxc_int32_t.c \
|
||||||
src/sc_timer_service.c \
|
src/sc_timer_service.c \
|
||||||
src-gen/Statechart.c \
|
src-gen/Statechart.c \
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:sgraph="http://www.yakindu.org/sct/sgraph/2.0.0">
|
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:sgraph="http://www.yakindu.org/sct/sgraph/2.0.0">
|
||||||
<sgraph:Statechart xmi:id="_jCYoMD-lEfCA8aDVRFe8Eg" specification="@EventDriven
@SuperSteps(no)

import: "./src/data_types.h"

interface:
	in event sensor: int32_t

	in event buttonPressed
	in event buttonReleased
	
	out event setMotorR: int32_t
	out event setMotorL: int32_t

	operation pid(sensor: int32_t, pid_vars: pid_vars_t): int32_t

internal:
	var speed: real
	var pid_vars: pid_vars_t" name="Statechart" domainID="com.yakindu.domain.c">
|
<sgraph:Statechart xmi:id="_jCYoMD-lEfCA8aDVRFe8Eg" specification="@EventDriven
@SuperSteps(no)

import: "./src/data_types.h"

interface:
	in event sensor: int32_t

	in event buttonPressed
	in event buttonReleased
	
	out event setMotorR: int32_t
	out event setMotorL: int32_t

	operation pid(sensor: int32_t, pid_vars: pid_vars_t): int32_t

internal:
	var speed: int32_t
	var pid_vars: pid_vars_t" name="Statechart" domainID="com.yakindu.domain.c">
|
||||||
<regions xmi:id="_jCcSkz-lEfCA8aDVRFe8Eg" name="main region">
|
<regions xmi:id="_jCcSkz-lEfCA8aDVRFe8Eg" name="main region">
|
||||||
<vertices xsi:type="sgraph:State" xmi:id="_IsdxcD-yEfCA8aDVRFe8Eg" name="on" incomingTransitions="_ff2psD-yEfCA8aDVRFe8Eg">
|
<vertices xsi:type="sgraph:State" xmi:id="_IsdxcD-yEfCA8aDVRFe8Eg" name="on" incomingTransitions="_ff2psD-yEfCA8aDVRFe8Eg">
|
||||||
<regions xmi:id="_IseYgD-yEfCA8aDVRFe8Eg" name="r1">
|
<regions xmi:id="_IseYgD-yEfCA8aDVRFe8Eg" name="r1">
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ static void run_cycle(Statechart* handle);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void statechart_internal_set_speed(Statechart* handle, sc_real value)
|
static void statechart_internal_set_speed(Statechart* handle, int32_t value)
|
||||||
;
|
;
|
||||||
static void statechart_internal_set_pid_vars(Statechart* handle, pid_vars_t value)
|
static void statechart_internal_set_pid_vars(Statechart* handle, pid_vars_t value)
|
||||||
;
|
;
|
||||||
|
|
@ -100,11 +100,11 @@ void statechart_init(Statechart* handle)
|
||||||
|
|
||||||
clear_in_events(handle);
|
clear_in_events(handle);
|
||||||
|
|
||||||
sc_observable_sc_real_init(&handle->iface.setMotorR);
|
sc_observable_int32_t_init(&handle->iface.setMotorR);
|
||||||
sc_observable_sc_real_init(&handle->iface.setMotorL);
|
sc_observable_int32_t_init(&handle->iface.setMotorL);
|
||||||
|
|
||||||
/* Default init sequence for statechart Statechart */
|
/* Default init sequence for statechart Statechart */
|
||||||
statechart_internal_set_speed(handle, 0.0);
|
statechart_internal_set_speed(handle, 0);
|
||||||
|
|
||||||
handle->isExecuting = bool_false;
|
handle->isExecuting = bool_false;
|
||||||
statechart_eventqueue_init(&handle->in_event_queue, handle->in_buffer, STATECHART_IN_EVENTQUEUE_BUFFERSIZE);
|
statechart_eventqueue_init(&handle->in_event_queue, handle->in_buffer, STATECHART_IN_EVENTQUEUE_BUFFERSIZE);
|
||||||
|
|
@ -287,7 +287,7 @@ static void run_cycle(Statechart* handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void statechart_raise_sensor(Statechart* handle, sc_real value)
|
void statechart_raise_sensor(Statechart* handle, int32_t value)
|
||||||
{
|
{
|
||||||
statechart_add_value_event_to_queue(&(handle->in_event_queue), Statechart_sensor, &value);
|
statechart_add_value_event_to_queue(&(handle->in_event_queue), Statechart_sensor, &value);
|
||||||
run_cycle(handle);
|
run_cycle(handle);
|
||||||
|
|
@ -306,17 +306,17 @@ void statechart_raise_buttonReleased(Statechart* handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sc_observable_sc_real* statechart_get_setMotorR(Statechart* handle)
|
sc_observable_int32_t* statechart_get_setMotorR(Statechart* handle)
|
||||||
{
|
{
|
||||||
return &handle->iface.setMotorR;
|
return &handle->iface.setMotorR;
|
||||||
}
|
}
|
||||||
sc_observable_sc_real* statechart_get_setMotorL(Statechart* handle)
|
sc_observable_int32_t* statechart_get_setMotorL(Statechart* handle)
|
||||||
{
|
{
|
||||||
return &handle->iface.setMotorL;
|
return &handle->iface.setMotorL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void statechart_internal_set_speed(Statechart* handle, sc_real value)
|
static void statechart_internal_set_speed(Statechart* handle, int32_t value)
|
||||||
{
|
{
|
||||||
handle->internal.speed = value;
|
handle->internal.speed = value;
|
||||||
}
|
}
|
||||||
|
|
@ -334,12 +334,12 @@ static void enact_main_region_on_r1_responding(Statechart* handle)
|
||||||
/* Entry action for state 'responding'. */
|
/* Entry action for state 'responding'. */
|
||||||
statechart_internal_set_speed(handle, statechart_pid(handle,handle->iface.sensor_value, handle->internal.pid_vars));
|
statechart_internal_set_speed(handle, statechart_pid(handle,handle->iface.sensor_value, handle->internal.pid_vars));
|
||||||
{
|
{
|
||||||
sc_real iface_setMotorL_value = handle->internal.speed;
|
int32_t iface_setMotorL_value = handle->internal.speed;
|
||||||
sc_observable_sc_real_next(&handle->iface.setMotorL, iface_setMotorL_value);
|
sc_observable_int32_t_next(&handle->iface.setMotorL, iface_setMotorL_value);
|
||||||
};
|
};
|
||||||
{
|
{
|
||||||
sc_real iface_setMotorR_value = handle->internal.speed;
|
int32_t iface_setMotorR_value = handle->internal.speed;
|
||||||
sc_observable_sc_real_next(&handle->iface.setMotorR, iface_setMotorR_value);
|
sc_observable_int32_t_next(&handle->iface.setMotorR, iface_setMotorR_value);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -348,12 +348,12 @@ static void enact_main_region_on_r1_sensor_error(Statechart* handle)
|
||||||
{
|
{
|
||||||
/* Entry action for state 'sensor_error'. */
|
/* Entry action for state 'sensor_error'. */
|
||||||
{
|
{
|
||||||
sc_real iface_setMotorL_value = 1;
|
int32_t iface_setMotorL_value = 1;
|
||||||
sc_observable_sc_real_next(&handle->iface.setMotorL, iface_setMotorL_value);
|
sc_observable_int32_t_next(&handle->iface.setMotorL, iface_setMotorL_value);
|
||||||
};
|
};
|
||||||
{
|
{
|
||||||
sc_real iface_setMotorR_value = -(1);
|
int32_t iface_setMotorR_value = -(1);
|
||||||
sc_observable_sc_real_next(&handle->iface.setMotorR, iface_setMotorR_value);
|
sc_observable_int32_t_next(&handle->iface.setMotorR, iface_setMotorR_value);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -858,7 +858,7 @@ static void statechart_event_value_init(statechart_event * ev, StatechartEventID
|
||||||
switch(name)
|
switch(name)
|
||||||
{
|
{
|
||||||
case Statechart_sensor:
|
case Statechart_sensor:
|
||||||
ev->value.Statechart_sensor_value = *((sc_real*)value);
|
ev->value.Statechart_sensor_value = *((int32_t*)value);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* do nothing */
|
/* do nothing */
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,9 @@ typedef struct StatechartTimeEvents StatechartTimeEvents;
|
||||||
#include "../src/data_types.h"
|
#include "../src/data_types.h"
|
||||||
#include "../src/sc_types.h"
|
#include "../src/sc_types.h"
|
||||||
#include "../src/sc_rxc.h"
|
#include "../src/sc_rxc.h"
|
||||||
|
#include "../src/sc_rxc_int32_t.h"
|
||||||
|
#include "../src/sc_rxc_int32_t.h"
|
||||||
|
#include "../src/sc_rxc_int32_t.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
@ -72,7 +75,7 @@ Header of the state machine 'Statechart'.
|
||||||
* Union of all possible event value types.
|
* Union of all possible event value types.
|
||||||
*/
|
*/
|
||||||
typedef union {
|
typedef union {
|
||||||
sc_real Statechart_sensor_value;
|
int32_t Statechart_sensor_value;
|
||||||
} statechart_event_value;
|
} statechart_event_value;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -125,11 +128,11 @@ typedef enum
|
||||||
struct StatechartIface
|
struct StatechartIface
|
||||||
{
|
{
|
||||||
sc_boolean sensor_raised;
|
sc_boolean sensor_raised;
|
||||||
sc_real sensor_value;
|
int32_t sensor_value;
|
||||||
sc_boolean buttonPressed_raised;
|
sc_boolean buttonPressed_raised;
|
||||||
sc_boolean buttonReleased_raised;
|
sc_boolean buttonReleased_raised;
|
||||||
sc_observable_sc_real setMotorR;
|
sc_observable_int32_t setMotorR;
|
||||||
sc_observable_sc_real setMotorL;
|
sc_observable_int32_t setMotorL;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -137,7 +140,7 @@ struct StatechartIface
|
||||||
/*! Type declaration of the data structure for the StatechartInternal interface scope. */
|
/*! Type declaration of the data structure for the StatechartInternal interface scope. */
|
||||||
struct StatechartInternal
|
struct StatechartInternal
|
||||||
{
|
{
|
||||||
sc_real speed;
|
int32_t speed;
|
||||||
pid_vars_t pid_vars;
|
pid_vars_t pid_vars;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -192,16 +195,16 @@ extern void statechart_trigger_without_event(Statechart* handle);
|
||||||
extern void statechart_raise_time_event(Statechart* handle, sc_eventid evid);
|
extern void statechart_raise_time_event(Statechart* handle, sc_eventid evid);
|
||||||
|
|
||||||
/*! Raises the in event 'sensor' that is defined in the default interface scope. */
|
/*! Raises the in event 'sensor' that is defined in the default interface scope. */
|
||||||
extern void statechart_raise_sensor(Statechart* handle, sc_real value);
|
extern void statechart_raise_sensor(Statechart* handle, int32_t value);
|
||||||
/*! Raises the in event 'buttonPressed' that is defined in the default interface scope. */
|
/*! Raises the in event 'buttonPressed' that is defined in the default interface scope. */
|
||||||
extern void statechart_raise_buttonPressed(Statechart* handle);
|
extern void statechart_raise_buttonPressed(Statechart* handle);
|
||||||
/*! Raises the in event 'buttonReleased' that is defined in the default interface scope. */
|
/*! Raises the in event 'buttonReleased' that is defined in the default interface scope. */
|
||||||
extern void statechart_raise_buttonReleased(Statechart* handle);
|
extern void statechart_raise_buttonReleased(Statechart* handle);
|
||||||
/*! Returns the observable for the out event 'setMotorR' that is defined in the default interface scope. */
|
/*! Returns the observable for the out event 'setMotorR' that is defined in the default interface scope. */
|
||||||
extern sc_observable_sc_real* statechart_get_setMotorR(Statechart* handle);
|
extern sc_observable_int32_t* statechart_get_setMotorR(Statechart* handle);
|
||||||
|
|
||||||
/*! Returns the observable for the out event 'setMotorL' that is defined in the default interface scope. */
|
/*! Returns the observable for the out event 'setMotorL' that is defined in the default interface scope. */
|
||||||
extern sc_observable_sc_real* statechart_get_setMotorL(Statechart* handle);
|
extern sc_observable_int32_t* statechart_get_setMotorL(Statechart* handle);
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ There are some constraints that have to be considered for the implementation of
|
||||||
- make sure that the execution time is as short as possible.
|
- make sure that the execution time is as short as possible.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern sc_real statechart_pid( Statechart* handle, const sc_real sensor, const pid_vars_t pid_vars);
|
extern int32_t statechart_pid( Statechart* handle, const int32_t sensor, const pid_vars_t pid_vars);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,18 +15,18 @@ static sc_timer_t timers[MAX_TIMERS];
|
||||||
static sc_timer_service_t timer_service;
|
static sc_timer_service_t timer_service;
|
||||||
|
|
||||||
// Observers are stateless (they just link to callbacks) so it's safe to use global variables here
|
// Observers are stateless (they just link to callbacks) so it's safe to use global variables here
|
||||||
static sc_single_subscription_observer_sc_integer observer_motorL;
|
static sc_single_subscription_observer_int32_t observer_motorL;
|
||||||
static sc_single_subscription_observer_sc_integer observer_motorR;
|
static sc_single_subscription_observer_int32_t observer_motorR;
|
||||||
|
|
||||||
static sc_integer motor_left_speed;
|
static int32_t motor_left_speed;
|
||||||
static sc_integer motor_right_speed;
|
static int32_t motor_right_speed;
|
||||||
|
|
||||||
// event handler callback functions
|
// event handler callback functions
|
||||||
void on_motorL(Statechart* sc, sc_integer value) {
|
void on_motorL(Statechart* sc, int32_t value) {
|
||||||
fprintf(stderr, "got event motorL: %f\n", value);
|
fprintf(stderr, "got event motorL: %f\n", value);
|
||||||
motor_left_speed = value;
|
motor_left_speed = value;
|
||||||
}
|
}
|
||||||
void on_motorR(Statechart* sc, sc_integer value) {
|
void on_motorR(Statechart* sc, int32_t value) {
|
||||||
fprintf(stderr, "got event motorR: %f\n", value);
|
fprintf(stderr, "got event motorR: %f\n", value);
|
||||||
motor_right_speed = value;
|
motor_right_speed = value;
|
||||||
}
|
}
|
||||||
|
|
@ -42,16 +42,16 @@ void controller_init(Statechart* sc) {
|
||||||
// subscribe to output events:
|
// subscribe to output events:
|
||||||
|
|
||||||
// motorL observer
|
// motorL observer
|
||||||
sc_single_subscription_observer_sc_integer_init(&observer_motorL, sc, (sc_observer_next_sc_integer_fp) on_motorL);
|
sc_single_subscription_observer_int32_t_init(&observer_motorL, sc, (sc_observer_next_int32_t_fp) on_motorL);
|
||||||
sc_single_subscription_observer_sc_integer_subscribe(&observer_motorL, statechart_get_setMotorL(sc));
|
sc_single_subscription_observer_int32_t_subscribe(&observer_motorL, statechart_get_setMotorL(sc));
|
||||||
|
|
||||||
// motorR observer
|
// motorR observer
|
||||||
sc_single_subscription_observer_sc_integer_init(&observer_motorR, sc, (sc_observer_next_sc_integer_fp) on_motorR);
|
sc_single_subscription_observer_int32_t_init(&observer_motorR, sc, (sc_observer_next_int32_t_fp) on_motorR);
|
||||||
sc_single_subscription_observer_sc_integer_subscribe(&observer_motorR, statechart_get_setMotorR(sc));
|
sc_single_subscription_observer_int32_t_subscribe(&observer_motorR, statechart_get_setMotorR(sc));
|
||||||
}
|
}
|
||||||
|
|
||||||
// to be called every 10 ms
|
// to be called every 10 ms
|
||||||
void controller_poll(sc_integer* _motor_left_speed, sc_integer* _motor_right_speed) {
|
void controller_poll(int32_t* _motor_left_speed, int32_t* _motor_right_speed) {
|
||||||
sc_time elapsed = 10; // ms
|
sc_time elapsed = 10; // ms
|
||||||
sc_timer_service_proceed(&timer_service, elapsed);
|
sc_timer_service_proceed(&timer_service, elapsed);
|
||||||
fprintf(stderr, "made 10ms step\n");
|
fprintf(stderr, "made 10ms step\n");
|
||||||
|
|
@ -61,13 +61,13 @@ void controller_poll(sc_integer* _motor_left_speed, sc_integer* _motor_right_spe
|
||||||
}
|
}
|
||||||
|
|
||||||
// finally, we need to implemented these functions (defined in "Statechart_required.h")
|
// finally, we need to implemented these functions (defined in "Statechart_required.h")
|
||||||
sc_integer statechart_pid(Statechart* handle, const sc_integer sensor, pid_vars_t pid_vars) {
|
int32_t statechart_pid(Statechart* handle, const int32_t sensor, pid_vars_t pid_vars) {
|
||||||
sc_integer error = TARGET_DIST - sensor; // is this correct?
|
int32_t error = TARGET_DIST - sensor; // is this correct?
|
||||||
return pid(pid_vars, error);
|
return pid(pid_vars, error);
|
||||||
}
|
}
|
||||||
// here you see the reason we need global variables for the timer service:
|
// here you see the reason we need global variables for the timer service:
|
||||||
// the signature of these functions is mandated by YAKINDU, and there is no 'timer service' parameter
|
// the signature of these functions is mandated by YAKINDU, and there is no 'timer service' parameter
|
||||||
void statechart_set_timer(Statechart *sc, const sc_eventid evid, const sc_integer time_ms, const sc_boolean periodic) {
|
void statechart_set_timer(Statechart *sc, const sc_eventid evid, const int32_t time_ms, const sc_boolean periodic) {
|
||||||
sc_timer_set(&timer_service, sc, evid, time_ms, periodic);
|
sc_timer_set(&timer_service, sc, evid, time_ms, periodic);
|
||||||
}
|
}
|
||||||
void statechart_unset_timer(Statechart *sc, const sc_eventid evid) {
|
void statechart_unset_timer(Statechart *sc, const sc_eventid evid) {
|
||||||
|
|
@ -76,5 +76,6 @@ void statechart_unset_timer(Statechart *sc, const sc_eventid evid) {
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
// find out how big the Statechart-struct is:
|
||||||
fprintf(stderr, "%d", sizeof(Statechart));
|
fprintf(stderr, "%d", sizeof(Statechart));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
6
robot_cdt/src/sc_rxc_int32_t.c
Normal file
6
robot_cdt/src/sc_rxc_int32_t.c
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
/* Generated by itemis CREATE code generator. */
|
||||||
|
|
||||||
|
#include "sc_rxc_int32_t.h"
|
||||||
|
|
||||||
|
define_sc_reactive_extensions(int32_t)
|
||||||
|
|
||||||
19
robot_cdt/src/sc_rxc_int32_t.h
Normal file
19
robot_cdt/src/sc_rxc_int32_t.h
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
/* Generated by itemis CREATE code generator. */
|
||||||
|
|
||||||
|
#ifndef SC_RXC_INT32_T_H_
|
||||||
|
#define SC_RXC_INT32_T_H_
|
||||||
|
|
||||||
|
#include "sc_rxc.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
declare_sc_reactive_extensions(int32_t)
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* SC_RXC_INT32_T_H_ */
|
||||||
Loading…
Add table
Add a link
Reference in a new issue