[tuxdroid-svn] r4754 - firmware/tuxcore/branches/demo
Status: Beta
Brought to you by:
ks156
|
From: ks156 <c2m...@c2...> - 2009-06-08 14:11:23
|
Author: ks156
Date: 2009-06-08 16:11:20 +0200 (Mon, 08 Jun 2009)
New Revision: 4754
Modified:
firmware/tuxcore/branches/demo/Makefile
firmware/tuxcore/branches/demo/global.h
firmware/tuxcore/branches/demo/motors.c
firmware/tuxcore/branches/demo/standalone.c
Log:
* Modified the original code to adpat it for the demo, with :
- A reduced the spinning amplitude (about 30 degrees)
- A reduced the spinning speed (PWM duty cycle : 40%)
- An advanced braking function
This code can be compiled with 'make DEMO=yes'
Some compensation values are defined in global.h. The spinning gearbox is not
symetrical, so a compensation must be done to retrieve the initial position.
These values should probably adapted for a specific Tux.
Modified: firmware/tuxcore/branches/demo/Makefile
===================================================================
--- firmware/tuxcore/branches/demo/Makefile 2009-06-08 14:07:22 UTC (rev 4753)
+++ firmware/tuxcore/branches/demo/Makefile 2009-06-08 14:11:20 UTC (rev 4754)
@@ -51,6 +51,10 @@
# Place -D or -U options here
CDEFS = -DF_CPU=8000000UL
+ifneq (,$(findstring yes, $(DEMO)))
+ CDEFS += -DDEMO
+endif
+
# Place -I options here
CINCS =
Modified: firmware/tuxcore/branches/demo/global.h
===================================================================
--- firmware/tuxcore/branches/demo/global.h 2009-06-08 14:07:22 UTC (rev 4753)
+++ firmware/tuxcore/branches/demo/global.h 2009-06-08 14:11:20 UTC (rev 4754)
@@ -31,6 +31,13 @@
#include "common/defines.h"
#include "common/api.h"
+#ifdef DEMO
+#define LEFT_COMP_CONT 8
+#define RIGHT_COMP_CONT -7
+#define LEFT_COMP LEFT_COMP_CONT
+#define RIGHT_COMP RIGHT_COMP_CONT
+#endif
+
/*
* Custom types
*/
Modified: firmware/tuxcore/branches/demo/motors.c
===================================================================
--- firmware/tuxcore/branches/demo/motors.c 2009-06-08 14:07:22 UTC (rev 4753)
+++ firmware/tuxcore/branches/demo/motors.c 2009-06-08 14:11:20 UTC (rev 4754)
@@ -34,7 +34,11 @@
* \name Motors PWM
* @{ */
uint8_t flippers_params_pwm = 5;
+#ifdef DEMO
+uint8_t spin_params_pwm = 1;
+#else
uint8_t spin_params_pwm = 5;
+#endif
/*! @} */
/**
@@ -111,6 +115,9 @@
{
LEFT,
RIGHT,
+#ifdef DEMO
+ NDEF,
+#endif
};
/** Spinning direction */
static uint8_t spin_direction;
@@ -248,11 +255,32 @@
cnt = 0;
}
else
+ {
+#ifdef DEMO
+ duration_movement |= SPIN_FLAG;
+ cnt = 0;
+#else
cnt = value;
+#endif
+ }
if (motor == MOT_SPIN_L)
+ {
+#ifdef DEMO
+ spin_stop_delay = (value * 40);
+ spin_left(value, 2);
+#else
spin_left(value, spin_params_pwm);
+#endif
+ }
else
+ {
+#ifdef DEMO
+ spin_stop_delay = (value * 40);
+ spin_right(value, 2);
+#else
spin_right(value, spin_params_pwm);
+#endif
+ }
}
}
@@ -272,8 +300,13 @@
}
else if (motor == (MOT_SPIN_L) || motor == (MOT_SPIN_R))
{
+#ifdef DEMO
+ spin_params_pwm = 2;
+ spin_PWM = 2;
+#else
spin_params_pwm = pwm;
spin_PWM = pwm;
+#endif
}
}
/** Counter for flipper interrupt suspend. */
@@ -861,6 +894,9 @@
stop_spin_motor();
}
+#ifdef DEMO
+static volatile uint8_t pwm_spin_tim = 0;
+#endif
/**
\brief Spin left for the \c angle amount.
\param angle Angle to turn, in 90° unit.
@@ -870,11 +906,19 @@
void spin_left(uint8_t const angle, uint8_t const pwm)
{
gStatus.mot |= GSTATUS_MOT_SPINL;
+#ifndef DEMO
spin_move_counter = angle;
+#endif
/* If the rotation direction is changing and we are not stopped exactly on
* the switch (position switch not pressed), we need to increment the angle
* value to prevent counting the first switch detection that will happen as
* soon as the rotation starts. */
+#ifdef DEMO
+ if ((spin_direction == RIGHT))
+ spin_stop_delay += LEFT_COMP;
+ else
+ spin_stop_delay += LEFT_COMP_CONT;
+#else
if ((spin_direction == RIGHT) && (PSW_SPIN_PIN & PSW_SPIN_MK))
if (spin_move_counter)
spin_move_counter++;
@@ -882,9 +926,13 @@
if (!(duration_movement & SPIN_FLAG))
spin_stop_delay = SPIN_TIMEOUT;
spin_PWM = pwm;
+#endif
spin_PWM_mask &= ~MOT_SPIN_R_MK;
spin_PWM_mask |= MOT_SPIN_L_MK;
PORTB |= portB_PWM_mask;
+#ifdef DEMO
+ pwm_spin_tim = 0;
+#endif
}
/**
@@ -896,19 +944,33 @@
void spin_right(uint8_t const angle, uint8_t const pwm)
{
gStatus.mot |= GSTATUS_MOT_SPINR;
+#ifndef DEMO
spin_move_counter = angle;
+#endif
/* If the rotation direction is changing and we are not stopped exactly on
* the switch (position switch not pressed), we need to increment the angle
* value to prevent counting the first switch detection that will happen as
* soon as the rotation starts. */
+#ifdef DEMO
+ if ((spin_direction == LEFT))
+ spin_stop_delay += RIGHT_COMP;
+ else
+ spin_stop_delay += RIGHT_COMP_CONT;
+#else
if ((spin_direction == LEFT) && (PSW_SPIN_PIN & PSW_SPIN_MK))
if (spin_move_counter)
spin_move_counter++;
spin_direction = RIGHT;
+ /*if (!(duration_movement & SPIN_FLAG))*/
+ /*spin_stop_delay = SPIN_TIMEOUT;*/
spin_PWM = pwm;
+#endif
spin_PWM_mask &= ~MOT_SPIN_L_MK;
spin_PWM_mask |= MOT_SPIN_R_MK;
PORTB |= portB_PWM_mask;
+#ifdef DEMO
+ pwm_spin_tim = 0;
+#endif
}
/**
\brief Spin position interrupt.
@@ -921,6 +983,7 @@
*/
ISR(SIG_INTERRUPT1)
{
+#ifndef DEMO
if (spin_move_counter)
{
spin_move_counter--;
@@ -938,6 +1001,7 @@
spin_PWM_mask |= MOT_SPIN_L_MK;
}
}
+#endif
}
/*! @} */
@@ -965,16 +1029,27 @@
/* Spin PWM
* Pulse is stopped here */
+#ifdef DEMO
+ if (pwm_spin_tim == spin_PWM)
+#else
if (pwm_tim == spin_PWM)
+#endif
MOT_SPIN_PT &= ~MOT_SPIN_MK;
/* PWM motor management
* Pulse is set here when pwm_tim is at maximum and is
* reset when pwm_tim equals the PWM value set by the user
*/
+#ifdef DEMO
+ if (pwm_spin_tim++ == PWM_PERIOD)
+#else
if (pwm_tim++ == PWM_PERIOD)
+#endif
{
pwm_tim = 0;
+#ifdef DEMO
+ pwm_spin_tim = 0;
+#endif
PORTB |= portB_PWM_mask; /* spin and flippers */
}
@@ -1022,10 +1097,35 @@
/* spin motor timeout */
if (spin_stop_delay)
{
+#ifdef DEMO
+ static uint8_t stopping = 0;
+#endif
spin_stop_delay--;
if (!spin_stop_delay)
{
+#ifdef DEMO
+ if (spin_direction == LEFT && stopping == 0)
+ {
+ stopping = 1;
+ stop_spin_motor();
+ spin_stop_delay = SPIN_BRAKING_DLY;
+ spin_PWM_mask |= MOT_SPIN_R_MK;
+ }
+ else if (spin_direction == RIGHT && stopping == 0)
+ {
+ stopping = 1;
+ stop_spin_motor();
+ spin_stop_delay = SPIN_BRAKING_DLY;
+ spin_PWM_mask |= MOT_SPIN_L_MK;
+ }
+ else
+ {
+ stopping = 0;
+ stop_spinning();
+ }
+#else
stop_spinning();
+#endif
}
}
Modified: firmware/tuxcore/branches/demo/standalone.c
===================================================================
--- firmware/tuxcore/branches/demo/standalone.c 2009-06-08 14:07:22 UTC (rev 4753)
+++ firmware/tuxcore/branches/demo/standalone.c 2009-06-08 14:11:20 UTC (rev 4754)
@@ -193,7 +193,6 @@
void standalone_behavior(void)
{
- static uint8_t mov_nbr = 1;
uint8_t ir_command, ir_toggle;
if (event_manager_flag)
@@ -223,6 +222,7 @@
if (tux_config.ir_feedback)
leds_toggle(2, 4);
+#ifdef DEMO
/* ALT KEYS */
if (alt_mode)
{
@@ -250,64 +250,16 @@
{
switch (ir_command)
{
- case K_0:
- case K_1:
- case K_2:
- case K_3:
- case K_4:
- case K_5:
- case K_6:
- case K_7:
- case K_8:
- case K_9:
- mov_nbr = ir_command;
- break;
- case K_UP:
- blink_eyes(mov_nbr);
- break;
- case K_OK:
- move_mouth(mov_nbr);
- break;
- case K_DOWN:
- wave_flippers(mov_nbr, 5);
- break;
case K_LEFT:
- spin_left(mov_nbr, spin_PWM);
+ motors_config(MOT_SPIN_L, 2);
+ motors_run(MOT_SPIN_L, 1, 0);
break;
case K_RIGHT:
- spin_right(mov_nbr, spin_PWM);
+ motors_config(MOT_SPIN_R, 2);
+ motors_run(MOT_SPIN_R, 1, 0);
break;
- case K_STOP:
- stop_spinning();
- stop_flippers();
- stop_mouth();
- break;
- case K_MUTE:
- tux_config.ir_feedback = !tux_config.ir_feedback;
- break;
- case K_CHANNELPLUS:
- led_pulse(LED_RIGHT, 1, 0);
- break;
- case K_VOLUMEPLUS:
- led_pulse(LED_LEFT, 1, 0);
- break;
- case K_FASTREWIND:
- if (spin_PWM)
- spin_PWM--;
- break;
- case K_FASTFORWARD:
- if (spin_PWM < 5)
- spin_PWM++;
- break;
- case K_PREVIOUS:
- if (flippers_PWM)
- flippers_PWM--;
- break;
- case K_NEXT:
- if (flippers_PWM < 5)
- flippers_PWM++;
- break;
}
}
+#endif
}
}
|