4 * This is a sample program for LATTEBOX NXTe(NXT Extension Kit Product)
\r
5 * and LSC(10-Axis Servo Kit Product)
\r
6 * <http://www.lattebox.com/product_list_e.php?pts_type=1>
\r
8 * It enables a NXT to control RC servo motors via I2C.
\r
9 * Maximum number of RC servos to be controlled is:
\r
10 * Number of NXT Sensor ports(4) * Number of NXTe channels (4) * Number of LSC channels (10)
\r
11 * = 160 RC Servos might be controlled by using a NXT!
\r
13 * Special thanks to Yu Yang <sog@lattebox.com>
\r
16 #include "kernel_id.h"
\r
17 #include "ecrobot_interface.h"
\r
20 /* OSEK declarations */
\r
23 /* NXT Sensor port configration */
\r
24 #define NXT_PORT NXT_PORT_S3
\r
26 /* LATTEBOX NXTe channel configuration */
\r
27 #define NXTe_CH0 0 /* channel 0 to 3 */
\r
29 /* LATTEBOX LSC servo channel configuration */
\r
30 #define SERVO_CH 1 /* servo channels: 1 to 10 */
\r
32 /* LEJOS OSEK hooks */
\r
33 void ecrobot_device_initialize()
\r
35 ecrobot_init_i2c(NXT_PORT, LOWSPEED_9V);
\r
38 void ecrobot_device_terminate()
\r
40 ecrobot_term_i2c(NXT_PORT);
\r
43 void user_1ms_isr_type2(void){}
\r
48 init_NXTe(NXT_PORT);
\r
49 sync_NXTeServo(NXT_PORT, NXTe_CH[NXTe_CH0]);
\r
50 load_NXTeServo(NXT_PORT, NXTe_CH[NXTe_CH0], ALL_SERVO_ENABLE);
\r
51 set_NXTeDelay(NXT_PORT, NXTe_CH[NXTe_CH0], SERVO_CH, 2);
\r
53 display_goto_xy(0, 0);
\r
54 display_string("NXTe Test");
\r
58 if (ecrobot_is_RUN_button_pressed())
\r
60 set_NXTeAngle(NXT_PORT, NXTe_CH[NXTe_CH0], SERVO_CH, MAX_ANGLE);
\r
61 while(read_NXTeMotion(NXT_PORT, NXTe_CH[NXTe_CH0]) != 0);
\r
63 display_goto_xy(0, 0);
\r
64 display_string("NXTe Test");
\r
65 display_goto_xy(0, 1);
\r
66 display_int(get_NXTeAngle(NXT_PORT, NXTe_CH[NXTe_CH0], SERVO_CH), 0);
\r
70 if (ecrobot_is_ENTER_button_pressed())
\r
72 set_NXTeAngle(NXT_PORT, NXTe_CH[NXTe_CH0], SERVO_CH, MIN_ANGLE);
\r
73 while(read_NXTeMotion(NXT_PORT, NXTe_CH[NXTe_CH0]) != 0);
\r
75 display_goto_xy(0, 0);
\r
76 display_string("NXTe Test");
\r
77 display_goto_xy(0, 1);
\r
78 display_int(get_NXTeAngle(NXT_PORT, NXTe_CH[NXTe_CH0], SERVO_CH), 0);
\r