fix everything
This commit is contained in:
parent
e8f246cfa5
commit
675efff85c
8 changed files with 71 additions and 41 deletions
|
|
@ -15,18 +15,18 @@ static sc_timer_t timers[MAX_TIMERS];
|
|||
static sc_timer_service_t timer_service;
|
||||
|
||||
// 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_sc_integer observer_motorR;
|
||||
static sc_single_subscription_observer_int32_t observer_motorL;
|
||||
static sc_single_subscription_observer_int32_t observer_motorR;
|
||||
|
||||
static sc_integer motor_left_speed;
|
||||
static sc_integer motor_right_speed;
|
||||
static int32_t motor_left_speed;
|
||||
static int32_t motor_right_speed;
|
||||
|
||||
// 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);
|
||||
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);
|
||||
motor_right_speed = value;
|
||||
}
|
||||
|
|
@ -42,16 +42,16 @@ void controller_init(Statechart* sc) {
|
|||
// subscribe to output events:
|
||||
|
||||
// motorL observer
|
||||
sc_single_subscription_observer_sc_integer_init(&observer_motorL, sc, (sc_observer_next_sc_integer_fp) on_motorL);
|
||||
sc_single_subscription_observer_sc_integer_subscribe(&observer_motorL, statechart_get_setMotorL(sc));
|
||||
sc_single_subscription_observer_int32_t_init(&observer_motorL, sc, (sc_observer_next_int32_t_fp) on_motorL);
|
||||
sc_single_subscription_observer_int32_t_subscribe(&observer_motorL, statechart_get_setMotorL(sc));
|
||||
|
||||
// motorR observer
|
||||
sc_single_subscription_observer_sc_integer_init(&observer_motorR, sc, (sc_observer_next_sc_integer_fp) on_motorR);
|
||||
sc_single_subscription_observer_sc_integer_subscribe(&observer_motorR, statechart_get_setMotorR(sc));
|
||||
sc_single_subscription_observer_int32_t_init(&observer_motorR, sc, (sc_observer_next_int32_t_fp) on_motorR);
|
||||
sc_single_subscription_observer_int32_t_subscribe(&observer_motorR, statechart_get_setMotorR(sc));
|
||||
}
|
||||
|
||||
// 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_timer_service_proceed(&timer_service, elapsed);
|
||||
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")
|
||||
sc_integer statechart_pid(Statechart* handle, const sc_integer sensor, pid_vars_t pid_vars) {
|
||||
sc_integer error = TARGET_DIST - sensor; // is this correct?
|
||||
int32_t statechart_pid(Statechart* handle, const int32_t sensor, pid_vars_t pid_vars) {
|
||||
int32_t error = TARGET_DIST - sensor; // is this correct?
|
||||
return pid(pid_vars, error);
|
||||
}
|
||||
// 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
|
||||
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);
|
||||
}
|
||||
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() {
|
||||
// find out how big the Statechart-struct is:
|
||||
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