Commit 578ce26a authored by Joanne Hugé's avatar Joanne Hugé

Remove motor control related features in packet-exchange

parent 645e9fb8
......@@ -61,10 +61,6 @@ typedef struct main_param {
int enable_tracing;
int enable_graph;
int interval_input;
int transition_time;
uint64_t target_interval;
} main_param_t;
// Static functions
......@@ -107,8 +103,6 @@ static struct timespec measures_start;
static struct timespec measures_end;
static char send_data[MAX_BUFFER_SIZE];
static int reverse_motors = 0;
static void help(char *argv[]) {
printf(
"Usage: %s [-a CPU -p PRIO -i USEC -r USEC -l N] [-d BUF_LEN | -c "
......@@ -130,37 +124,10 @@ static void help(char *argv[]) {
" -v Verbose\n"
" -T Enable tracing until deadline is missed\n"
" -S Enable tracing until threshold is reached\n"
" -U Interactive interval change\n"
"\n",
argv[0]);
}
static double i_to_rps(int i) {
return ((double)USEC_PER_SEC) / (MOTOR_STEPS * i);
}
static int rps_to_i(double rps) {
return USEC_PER_SEC / (MOTOR_STEPS * rps);
}
static void *print_thread(void *p) {
(void)p;
for (;;) {
if (thread_params.max_cycles &&
nb_cycles >= ((unsigned int)thread_params.max_cycles))
break;
printf("RPS: %5F RPS Target: %5F s/100 RPS %5d\n", i_to_rps(thread_params.interval / 1000),
i_to_rps(main_params.target_interval),
main_params.transition_time);
printf("\033[%dA", 1);
usleep(100000);
}
pthread_exit(NULL);
}
/*
* Real-time thread:
* - Sends packets at a regular intervall
......@@ -175,9 +142,6 @@ static void *packet_sending_thread(void *p) {
uint64_t next_increment = 0;
uint64_t end_t = 0;
uint64_t cur_t = 0;
uint64_t i_t = 0;
uint64_t i_s = thread_params.interval / 1000;
uint64_t i_c = thread_params.interval / 1000;
// Set thread CPU affinity
if (thread_params.affinity_cpu != -1) {
......@@ -254,12 +218,6 @@ static void *packet_sending_thread(void *p) {
if (thread_params.enable_send_ts) {
tx_data = next.tv_sec * NSEC_PER_SEC + next.tv_nsec;
tx_data += thread_params.send_ts_delay;
if(reverse_motors) {
reverse_motors = 0;
tx_data = 17;
}
}
// Update statistics
......@@ -284,65 +242,6 @@ static void *packet_sending_thread(void *p) {
}
}
if(main_params.interval_input && (thread_params.interval != (main_params.target_interval * 1000))) {
i_c = thread_params.interval / 1000;
// If target interval changed
if(i_t != main_params.target_interval) {
i_t = main_params.target_interval;
i_s = i_c;
cur_t = 0;
next_increment = 0;
if(i_t < i_s)
end_t = (main_params.transition_time * USEC_PER_SEC * USEC_PER_SEC * (i_c - i_t)) / (100 * MOTOR_STEPS * i_t * i_c);
else
end_t = (main_params.transition_time * USEC_PER_SEC * USEC_PER_SEC * (i_t - i_c)) / (100 * MOTOR_STEPS * i_t * i_c);
}
if(next_increment) {
if(cur_t > next_increment) {
i_c += i_t < i_s ? -1 : 1;
next_increment = 0;
}
} else {
uint64_t next_i = i_t < i_s ? i_c - 1 : i_c + 1;
// Compute time at which we will need to increment / decrement the interval
if(i_t < i_s)
next_increment = (end_t * i_t * (i_s - next_i)) / ((i_s - i_t) * next_i);
else
next_increment = (end_t * i_t * (next_i - i_s)) / ((i_t - i_s) * next_i);
// If next increment time is before next interval
if(next_increment < cur_t + i_c) {
if(i_t < i_s) {
i_c = (i_t * i_s * end_t) / ((i_s - i_t) * (cur_t + i_c) + end_t * i_t);
i_c = i_c < i_t ? i_t : i_c;
}
else {
i_c = (i_t * i_s * end_t) / (end_t * i_t - (i_t - i_s) * (cur_t + i_c));
i_c = i_c > i_t ? i_t : i_c;
}
next_increment = 0;
}
}
cur_t += i_c;
if(i_c < 50) {
fprintf(stderr, "Interval too small, exiting..\n");
exit(EXIT_FAILURE);
}
if(i_c > USEC_PER_SEC) {
fprintf(stderr, "Interval too big, exiting..\n");
exit(EXIT_FAILURE);
}
thread_params.interval = i_c * 1000;
}
previous = current;
}
......@@ -355,28 +254,6 @@ invalid_ts:
exit(EXIT_FAILURE);
}
static void motor_input(void) {
char user_input[255];
int v;
scanf("%s", user_input);
switch(user_input[0]) {
case 'a':
v = atoi(user_input + 1);
if(v)
main_params.transition_time = v;
break;
case 'r':
reverse_motors = 1;
break;
default:
v = rps_to_i(strtod(user_input, NULL));
if(v)
main_params.target_interval = v;
break;
}
}
/*
* Main thread:
* - Has non-real time priority
......@@ -401,7 +278,6 @@ int main(int argc, char *argv[]) {
main_params.verbose = 0;
main_params.enable_tracing = 0;
main_params.enable_graph = 0;
main_params.interval_input = 0;
egress_params.packet_priority = 3;
egress_params.tx_buffer_len = 1024;
egress_params2.packet_priority = 3;
......@@ -421,8 +297,6 @@ int main(int argc, char *argv[]) {
// Process bash options
process_options(argc, argv);
main_params.target_interval = thread_params.interval / 1000;
set_latency_target();
egress_params.use_etf = enable_etf;
......@@ -490,22 +364,11 @@ int main(int argc, char *argv[]) {
if (pthread_create(&thread, &attr, packet_sending_thread, NULL))
error(EXIT_FAILURE, errno, "Couldn't create packet sending thread");
if(main_params.interval_input) {
// Create the print thread
if (pthread_create(&print_pthread, NULL, print_thread, NULL))
error(EXIT_FAILURE, errno, "Couldn't create print thread");
}
// Verbose loop
for (;;) {
usleep(main_params.refresh_rate);
if (main_params.interval_input) {
motor_input();
}
else if (main_params.verbose) {
if (main_params.verbose) {
// RTT stats printing
if (tsn_task == RTT_TASK) {
// N_CYCLES, RTT min / avg / max
......@@ -626,7 +489,7 @@ static void sighand(int sig_num) {
*/
static void process_options(int argc, char *argv[]) {
for (;;) {
int c = getopt(argc, argv, "a:bc:d:e:ghi:l:p:q:r:s:tvTS:U:");
int c = getopt(argc, argv, "a:bc:d:e:ghi:l:p:q:r:s:tvTS:");
if (c == -1) break;
......@@ -692,10 +555,6 @@ static void process_options(int argc, char *argv[]) {
thread_params.enable_threshold_tracing = 1;
thread_params.threshold = atoi(optarg);
break;
case 'U':
main_params.interval_input = 1;
main_params.transition_time = atoi(optarg);
break;
}
}
......
Markdown is supported
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