Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed WattBob_TextLCD globals
Revision 2:ea2d1441d485, committed 2011-11-29
- Comitter:
- Nurbol
- Date:
- Tue Nov 29 00:24:09 2011 +0000
- Parent:
- 1:a91950a8e20f
- Commit message:
Changed in this revision
--- a/cmd_io.cpp Fri Nov 25 17:22:31 2011 +0000
+++ b/cmd_io.cpp Tue Nov 29 00:24:09 2011 +0000
@@ -148,6 +148,10 @@
if (command->nos_data == 2) {
sprintf(buffer, "%u %u\n", (int)command->result_data[0], (int)command->result_data[1]);
}
+ if (command->nos_data == 7) {
+ sprintf(buffer, "%u %u %u %u %u %u %u\n", (int)command->result_data[0], (int)command->result_data[1], (int)command->result_data[2], (int)command->result_data[3],
+ (int)command->result_data[4], (int)command->result_data[5], (int)command->result_data[6]);
+ }
//
// send string
//
--- a/cmd_io.lib Fri Nov 25 17:22:31 2011 +0000 +++ b/cmd_io.lib Tue Nov 29 00:24:09 2011 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/Nurbol/code/cmd_io/#9f108fca5c3b +http://mbed.org/users/Nurbol/code/cmd_io/#c099ce00dd9a
--- a/globals.lib Fri Nov 25 17:22:31 2011 +0000 +++ b/globals.lib Tue Nov 29 00:24:09 2011 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/Nurbol/code/globals/#ca74c2573e8d +http://mbed.org/users/Nurbol/code/globals/#804ea67c7003
--- a/main.cpp Fri Nov 25 17:22:31 2011 +0000
+++ b/main.cpp Tue Nov 29 00:24:09 2011 +0000
@@ -59,6 +59,7 @@
bool Position2_1p;
bool Position1_2p;
bool Position2_2p;
+bool Motor;
bool bSort_Mode; //to use in the code to define the mode
bool bMaint_Mode;//to use in the code to define the mode
@@ -100,7 +101,7 @@
//******************************************************************************
// Defined GLOBAL variables and structures
//
-CMD_STRUCT ext_cmd, commandcounter2; // structure to hold command data
+CMD_STRUCT ext_cmd; // structure to hold command data
STAT_STRUCT ext_stat; // structure to hold status reply
@@ -126,7 +127,7 @@
par_port->write_bit(1,BL_BIT); // turn LCD backlight ON
lcd->cls();
lcd->locate(0,0);
- lcd->printf("W3C: Wheel Coin Counter Company");
+ lcd->printf("W3C");
servo_0.period(0.020); // servo requires a 20ms period, common for all 5 servo objects
last_servo = SERVO_UNKNOWN;
@@ -178,7 +179,7 @@
pulse_width = 0; // convert angle to pulse width
}
else{
- pulse_width = 1000 + (command->param[1] * 1000) / MAX_SERVO_ANGLE; // convert angle to pulse width
+ pulse_width = 1000 + (command->param[1] * 1000) / 90; // convert angle to pulse width
}
@@ -198,14 +199,22 @@
// return last servo number
//
case READ_CMD :
- command->nos_data = 2;// no data to be returned
- if((bSort_Mode == 0)&&(bMaint_Mode == 1)){
+
+ if((bSort_Mode == 0)&&(bMaint_Mode == 1)){
+ command->nos_data = 2;// no data to be returned
command->result_data[0] = valueLED1;
command->result_data[1] = valueLED2;
}
- else if((bSort_Mode == 1)&&(bMaint_Mode == 0)){
- command->result_data[0] = counter1p;
- command->result_data[1] = counter2p;
+ else if((bSort_Mode == 1)&&(bMaint_Mode == 0)){
+ command->nos_data = 7;// no data to be returned
+ command->result_data[0] = valueLED1;// counter1p;
+ command->result_data[1] = valueLED2;// counter2p;
+ command->result_data[2] = Motor;
+ command->result_data[3] = Position1_1p;
+ command->result_data[4] = Position2_1p;
+ command->result_data[5] = Position1_2p;
+ command->result_data[6] = Position2_2p;
+ send_data(&ext_cmd);
}
break;
@@ -216,15 +225,40 @@
bSort_Mode = 0;
bMaint_Mode = 1;
servo_4.pulsewidth_us(0);
- servo_0.pulsewidth_us(1000 + (0 * 1000) / 90);
- servo_5.pulsewidth_us(1000 + (0 * 1000) / 90);
+ servo_0.pulsewidth_us(0);
+ servo_5.pulsewidth_us(0);
+ lcd->cls();
+ lcd->locate(0,0);
+ lcd->printf("W3C");
+ lcd->locate(1,0);
+ lcd->printf("maintenance mode");
break;
case SORT_MODE :
bSort_Mode = 1;
bMaint_Mode = 0;
+ lcd->cls();
+ lcd->locate(0,0);
+ lcd->printf("W3C");
+ lcd->locate(1,0);
+ lcd->printf("sort mode");
break;
+
+//
+// Urgency mode
+//
+ case URGENCY :
+ servo_4.pulsewidth_us(0);
+ servo_0.pulsewidth_us(0);
+ servo_5.pulsewidth_us(0);
+ lcd->cls();
+ lcd->locate(0,0);
+ lcd->printf("W3C");
+ lcd->locate(1,0);
+ lcd->printf("urgency mode");
+ break;
+
//
// catch any problems
//
@@ -284,6 +318,7 @@
Position2_1p = 0;
Position1_2p = 1;
Position2_2p = 0;
+ Motor = 1;
led3 = 0;
led4 = 0;
counter1p.read();
@@ -305,12 +340,14 @@
wait(1);
Position1_1p = 0;
Position2_1p = 1;
+ Motor = 0;
if((Position2_1p == 1)&&(counter1p < 0.5)){
state = 2;
}
break;
case 2: // state 2 if servo 1p is in position 2
servo_4.pulsewidth_us(1000 + (25 * 1000) / 90); // motor is run
+ Motor = 1;
counter1p.read();
if(counter1p > 0.5){
state = 3;
@@ -318,6 +355,7 @@
break;
case 3: // state 3 if counter 1p = 1
servo_4.pulsewidth_us(0); // motor stop
+ Motor = 0;
led3 = 1;
if(SW1p == 1){ // wait SW 1p to go to the initial state
state = 0;
@@ -329,12 +367,14 @@
wait(1);
Position1_2p = 0;
Position2_2p = 1;
+ Motor = 0;
if((Position2_2p == 1)&&(counter2p < 0.5)){
state = 5;
}
break;
case 5: // state 5 if servo 2p is in position 2
servo_4.pulsewidth_us(1000 + (25 * 1000) / 90); // motor run
+ Motor = 1;
counter2p.read();
if(counter2p > 0.5){
state = 6;
@@ -342,6 +382,7 @@
break;
case 6: // state 6 if counter 2p = 1
servo_4.pulsewidth_us(0); // motor stop
+ Motor = 0;
led4 = 1;
if(SW2p == 1){ // wait SW 2p to go to the initial state
state = 0;
@@ -391,9 +432,9 @@
// If there is a problem, then return status code only and wait for next command.
//
parse_cmd(&ext_cmd);
- lcd->locate(1,0); lcd->printf(ext_cmd.cmd_str);
+ // lcd->locate(1,0); lcd->printf(ext_cmd.cmd_str);
if ((ext_cmd.result_status != OK) && (ext_cmd.cmd_code != TEXT_CMD)){
- lcd->locate(1,0); lcd->printf("parse : error");
+ lcd->cls(); lcd->locate(0,0); lcd->printf("W3C"); lcd->locate(1,0); lcd->printf("parse : error");
send_status(ext_cmd.result_status);
continue;
}
@@ -402,6 +443,7 @@
//
process_cmd(&ext_cmd);
reply_to_cmd(&ext_cmd);
+