engine ctrl example

This commit is contained in:
tkl 2016-08-10 12:13:58 +02:00
parent 0e891d545e
commit 3063445932

View File

@ -62,27 +62,48 @@ struct thread_context th_ctx;
static void th_func(void *arg) static void th_func(void *arg)
{ {
unsigned int duty = 0; unsigned int duty = 0;
/* open enable pins */
open(drive_ctrl.left_forward->enable); open(drive_ctrl.left_forward->enable);
write(drive_ctrl.left_forward->enable, "0", 1); write(drive_ctrl.left_forward->enable, "0", 1);
open(drive_ctrl.left_forward->pwm);
open(drive_ctrl.left_backward->enable); open(drive_ctrl.left_backward->enable);
write(drive_ctrl.left_backward->enable, "0", 1); 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_forward->enable, "1", 1);
write(drive_ctrl.left_backward->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) { while(1) {
duty = 0; duty = 0;
ioctl(drive_ctrl.left_backward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&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);
for(duty = 0; duty < 100; duty++) { for(duty = 0; duty < 100; duty++) {
ioctl(drive_ctrl.left_forward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&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); sleep_ms(100);
} }
duty = 0; duty = 0;
ioctl(drive_ctrl.left_forward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&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); sleep_ms(100);
for(duty = 0; duty < 100; duty++) { for(duty = 0; duty < 100; duty++) {
ioctl(drive_ctrl.left_backward->pwm, IOCTL_PWM_SET_DUTY_CYCLE, (const void *)&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);
} }
sleep_ms(100); sleep_ms(100);