From 3063445932952b9917ccca9a62e5b2d231221fd2 Mon Sep 17 00:00:00 2001 From: tkl Date: Wed, 10 Aug 2016 12:13:58 +0200 Subject: [PATCH] engine ctrl example --- source/test/pwm/main.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/source/test/pwm/main.c b/source/test/pwm/main.c index 22853aa..482e65e 100644 --- a/source/test/pwm/main.c +++ b/source/test/pwm/main.c @@ -62,27 +62,48 @@ struct thread_context th_ctx; static void th_func(void *arg) { unsigned int duty = 0; + + /* open enable pins */ open(drive_ctrl.left_forward->enable); write(drive_ctrl.left_forward->enable, "0", 1); - open(drive_ctrl.left_forward->pwm); open(drive_ctrl.left_backward->enable); write(drive_ctrl.left_backward->enable, "0", 1); - open(drive_ctrl.left_backward->pwm); + open(drive_ctrl.right_forward->enable); + write(drive_ctrl.right_forward->enable, "0", 1); + open(drive_ctrl.right_backward->enable); + write(drive_ctrl.right_backward->enable, "0", 1); + /* open pwm's*/ + open(drive_ctrl.left_backward->pwm); + ioctl(drive_ctrl.left_backward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty); + open(drive_ctrl.left_forward->pwm); + ioctl(drive_ctrl.left_forward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty); + open(drive_ctrl.right_backward->pwm); + ioctl(drive_ctrl.right_backward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty); + open(drive_ctrl.right_forward->pwm); + ioctl(drive_ctrl.right_forward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty); + + /* enable enable pins */ write(drive_ctrl.left_forward->enable, "1", 1); write(drive_ctrl.left_backward->enable, "1", 1); + write(drive_ctrl.right_forward->enable, "1", 1); + write(drive_ctrl.right_backward->enable, "1", 1); while(1) { duty = 0; ioctl(drive_ctrl.left_backward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty); + ioctl(drive_ctrl.right_backward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty); for(duty = 0; duty < 100; duty++) { ioctl(drive_ctrl.left_forward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty); + ioctl(drive_ctrl.right_forward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty); sleep_ms(100); } duty = 0; ioctl(drive_ctrl.left_forward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty); + ioctl(drive_ctrl.right_forward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty); sleep_ms(100); for(duty = 0; duty < 100; duty++) { ioctl(drive_ctrl.left_backward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty); + ioctl(drive_ctrl.right_backward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&duty); sleep_ms(100); } sleep_ms(100);