source: rtos_arduino/trunk/arduino_lib/libraries/Robot_Motor/src/ArduinoRobotMotorBoard.h@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 2.9 KB
Line 
1#ifndef ArduinoRobot_h
2#define ArduinoRobot_h
3
4#include "EasyTransfer2.h"
5#include "Multiplexer.h"
6#include "LineFollow.h"
7//#include "IRremote.h"
8
9#if ARDUINO >= 100
10#include "Arduino.h"
11#else
12#include "WProgram.h"
13#endif
14
15//Command code
16#define COMMAND_SWITCH_MODE 0
17#define COMMAND_RUN 10
18#define COMMAND_MOTORS_STOP 11
19#define COMMAND_ANALOG_WRITE 20
20#define COMMAND_DIGITAL_WRITE 30
21#define COMMAND_ANALOG_READ 40
22#define COMMAND_ANALOG_READ_RE 41
23#define COMMAND_DIGITAL_READ 50
24#define COMMAND_DIGITAL_READ_RE 51
25#define COMMAND_READ_IR 60
26#define COMMAND_READ_IR_RE 61
27#define COMMAND_ACTION_DONE 70
28#define COMMAND_READ_TRIM 80
29#define COMMAND_READ_TRIM_RE 81
30#define COMMAND_PAUSE_MODE 90
31#define COMMAND_LINE_FOLLOW_CONFIG 100
32
33
34//component codename
35#define CN_LEFT_MOTOR 0
36#define CN_RIGHT_MOTOR 1
37#define CN_IR 2
38
39//motor board modes
40#define MODE_SIMPLE 0
41#define MODE_LINE_FOLLOW 1
42#define MODE_ADJUST_MOTOR 2
43#define MODE_IR_CONTROL 3
44
45//bottom TKs, just for communication purpose
46#define B_TK1 201
47#define B_TK2 202
48#define B_TK3 203
49#define B_TK4 204
50
51/*
52A message structure will be:
53switch mode (2):
54 byte COMMAND_SWITCH_MODE, byte mode
55run (5):
56 byte COMMAND_RUN, int speedL, int speedR
57analogWrite (3):
58 byte COMMAND_ANALOG_WRITE, byte codename, byte value;
59digitalWrite (3):
60 byte COMMAND_DIGITAL_WRITE, byte codename, byte value;
61analogRead (2):
62 byte COMMAND_ANALOG_READ, byte codename;
63analogRead _return_ (4):
64 byte COMMAND_ANALOG_READ_RE, byte codename, int value;
65digitalRead (2):
66 byte COMMAND_DIGITAL_READ, byte codename;
67digitalRead _return_ (4):
68 byte COMMAND_DIGITAL_READ_RE, byte codename, int value;
69read IR (1):
70 byte COMMAND_READ_IR;
71read IR _return_ (9):
72 byte COMMAND_READ_IR_RE, int valueA, int valueB, int valueC, int valueD;
73
74
75*/
76
77class RobotMotorBoard:public LineFollow{
78 public:
79 RobotMotorBoard();
80 void begin();
81
82 void process();
83
84 void parseCommand();
85
86 int IRread(uint8_t num);
87
88 void setMode(uint8_t mode);
89 void pauseMode(bool onOff);
90
91 void motorsWrite(int speedL, int speedR);
92 void motorsWritePct(int speedLpct, int speedRpct);//write motor values in percentage
93 void motorsStop();
94 private:
95 float motorAdjustment;//-1.0 ~ 1.0, whether left is lowered or right is lowered
96
97 //convert codename to actual pins
98 uint8_t parseCodename(uint8_t codename);
99 uint8_t codenameToAPin(uint8_t codename);
100
101 void stopCurrentActions();
102 //void sendCommand(byte command,byte codename,int value);
103
104 void _analogWrite(uint8_t codename, int value);
105 void _digitalWrite(uint8_t codename, bool value);
106 void _analogRead(uint8_t codename);
107 void _digitalRead(uint8_t codename);
108 int _IRread(uint8_t num);
109 void _readIR();
110 void _readTrim();
111
112 void _refreshMotorAdjustment();
113
114 Multiplexer IRs;
115 uint8_t mode;
116 uint8_t isPaused;
117 EasyTransfer2 messageIn;
118 EasyTransfer2 messageOut;
119
120 //Line Following
121 void reportActionDone();
122};
123
124extern RobotMotorBoard RobotMotor;
125
126#endif
Note: See TracBrowser for help on using the repository browser.