-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b91d98
commit 8279001
Showing
9 changed files
with
394 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ | |
*.pyc | ||
|
||
scripts/ckpts/* | ||
.vscode/settings.json | ||
.vscode/c_cpp_properties.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#include "MoveControl.h" | ||
#define UP 1 | ||
#define DOWN 2 | ||
#define MIDDLE 3 | ||
|
||
MoveControl::MoveControl() | ||
{ | ||
flag=false; | ||
char portName[20]="/dev/ttyUSB0"; | ||
int baud=100000; | ||
if(SP.init_8n1(portName)&&SP.openPort(baud)==true) | ||
{ | ||
printf("\nSystem is Online\n" ); | ||
flag=true; | ||
} | ||
setbuf(stdin,NULL); | ||
CH0=1024; | ||
CH1=1024; | ||
CH2=1024; | ||
CH3=1024; | ||
S1=3; | ||
S2=1; | ||
} | ||
|
||
MoveControl::~MoveControl() | ||
{ | ||
SP.closePort(); | ||
} | ||
|
||
|
||
bool MoveControl::Attack_Mode_Change() | ||
{ | ||
for(int i=1;i<=3;i++) | ||
{ | ||
S1=MIDDLE; | ||
Send_Message(); | ||
usleep(14*1000); | ||
} | ||
for(int i=1;i<=3;i++) | ||
{ | ||
S1=UP; | ||
Send_Message(); | ||
usleep(14*1000); | ||
} | ||
for(int i=1;i<=3;i++) | ||
{ | ||
S1=MIDDLE; | ||
Send_Message(); | ||
usleep(14*1000); | ||
} | ||
} | ||
|
||
bool MoveControl::Attack(int cnt) | ||
{ | ||
Attack_Mode_Change(); | ||
for(int j=1;j<=cnt;j++) | ||
{ | ||
for(int i=1;i<=30;i++) | ||
{ | ||
S1=MIDDLE; | ||
Send_Message(); | ||
usleep(14*1000); | ||
} | ||
for(int i=1;i<=30;i++) | ||
{ | ||
S1=DOWN; | ||
Send_Message(); | ||
usleep(14*1000); | ||
} | ||
for(int i=1;i<=30;i++) | ||
{ | ||
S1=MIDDLE; | ||
Send_Message(); | ||
usleep(30*1000); | ||
} | ||
} | ||
Attack_Mode_Change(); | ||
} | ||
|
||
|
||
bool MoveControl::Forward_Back(int f_b) | ||
{ | ||
CH1=1024+(f_b/100.0)*660; | ||
} | ||
|
||
bool MoveControl::Right_Left(int r_l) | ||
{ | ||
CH0=1024+(r_l/100.0)*660; | ||
} | ||
|
||
bool MoveControl::Up_Down(int u_d) | ||
{ | ||
CH3=1024+(u_d/100.0)*660; | ||
} | ||
|
||
bool MoveControl::Right_Left_Rotation(int r_l_R) | ||
{ | ||
CH2=1024+(r_l_R/100.0)*660; | ||
} | ||
|
||
bool MoveControl::Send_Message() | ||
{ | ||
char sendstr[18]; | ||
for (int i=6;i<=17;i++) | ||
{ | ||
sendstr[i] = 0b00000000; | ||
} | ||
sendstr[0]=CH0; | ||
sendstr[1]=(CH0>>8)+(CH1<<3); | ||
sendstr[2]=(CH1>>5)+(CH2<<6); | ||
sendstr[3]=CH2>>2; | ||
sendstr[4]=(CH2>>10)+(CH3<<1); | ||
sendstr[5]=(CH3>>7)+(S1<<6)+(S2<<4); | ||
SP.writeData(sendstr,18); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include "SerialPort.h" | ||
|
||
class MoveControl | ||
{ | ||
public: | ||
MoveControl(); | ||
~MoveControl(); | ||
|
||
bool flag; | ||
int CH0; | ||
int CH1; | ||
int CH2; | ||
int CH3; | ||
int S1; | ||
int S2; | ||
|
||
bool Send_Message(); | ||
bool Attack_Mode_Change(); | ||
bool Attack(int n); | ||
bool Forward_Back(int f_b); | ||
bool Right_Left(int r_l); | ||
bool Up_Down(int u_d); | ||
bool Right_Left_Rotation(int r_l_R); | ||
private: | ||
SerialPort SP; | ||
}; |
Oops, something went wrong.