command完成
parent
3bca145d5f
commit
b4dbfe735f
|
@ -0,0 +1,28 @@
|
|||
#include "Command.h"
|
||||
|
||||
void Command::run(char* str){
|
||||
for(int i=0; i < call_count; i++){
|
||||
if(isSentinel(call_ids[i],str)){ // case : call_ids = "T2" str = "T215.15"
|
||||
call_list[i](str+strlen(call_ids[i])); // get 15.15 input function
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void Command::add(char* id, CommandCallback onCommand){
|
||||
call_list[call_count] = onCommand;
|
||||
call_ids[call_count] = id;
|
||||
call_count++;
|
||||
}
|
||||
void Command::scalar(float* value, char* user_cmd){
|
||||
*value = atof(user_cmd);
|
||||
}
|
||||
bool Command::isSentinel(char* ch,char* str)
|
||||
{
|
||||
char s[strlen(ch)+1];
|
||||
strncpy(s,str,strlen(ch));
|
||||
s[strlen(ch)] = '\0'; //strncpy need add end '\0'
|
||||
if(strcmp(ch, s) == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#include <Arduino.h>
|
||||
// callback function pointer definiton
|
||||
typedef void (* CommandCallback)(char*); //!< command callback function pointer
|
||||
class Command
|
||||
{
|
||||
public:
|
||||
void add(char* id , CommandCallback onCommand);
|
||||
void run(char* str);
|
||||
void scalar(float* value, char* user_cmd);
|
||||
bool isSentinel(char* ch,char* str);
|
||||
private:
|
||||
// Subscribed command callback variables
|
||||
CommandCallback call_list[20];//!< array of command callback pointers - 20 is an arbitrary number
|
||||
char* call_ids[20]; //!< added callback commands
|
||||
int call_count;//!< number callbacks that are subscribed
|
||||
|
||||
};
|
|
@ -0,0 +1,11 @@
|
|||
#include "Command.h"
|
||||
Command command;//声明一个自己的该类的对象
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
#include "Command.h"
|
||||
|
||||
void Command::run(char* str){
|
||||
for(int i=0; i < call_count; i++){
|
||||
if(isSentinel(call_ids[i],str)){ // case : call_ids = "T2" str = "T215.15"
|
||||
call_list[i](str+strlen(call_ids[i])); // get 15.15 input function
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void Command::add(char* id, CommandCallback onCommand){
|
||||
call_list[call_count] = onCommand;
|
||||
call_ids[call_count] = id;
|
||||
call_count++;
|
||||
}
|
||||
void Command::scalar(float* value, char* user_cmd){
|
||||
*value = atof(user_cmd);
|
||||
}
|
||||
bool Command::isSentinel(char* ch,char* str)
|
||||
{
|
||||
char s[strlen(ch)+1];
|
||||
strncpy(s,str,strlen(ch));
|
||||
s[strlen(ch)] = '\0'; //strncpy need add end '\0'
|
||||
if(strcmp(ch, s) == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#include <Arduino.h>
|
||||
// callback function pointer definiton
|
||||
typedef void (* CommandCallback)(char*); //!< command callback function pointer
|
||||
class Command
|
||||
{
|
||||
public:
|
||||
void add(char* id , CommandCallback onCommand);
|
||||
void run(char* str);
|
||||
void scalar(float* value, char* user_cmd);
|
||||
bool isSentinel(char* ch,char* str);
|
||||
private:
|
||||
// Subscribed command callback variables
|
||||
CommandCallback call_list[20];//!< array of command callback pointers - 20 is an arbitrary number
|
||||
char* call_ids[20]; //!< added callback commands
|
||||
int call_count;//!< number callbacks that are subscribed
|
||||
|
||||
};
|
|
@ -7,6 +7,7 @@ Deng's FOC 闭环速度控制例程 测试库:SimpleFOC 2.1.1 测试硬件:
|
|||
默认PID针对的电机是 GB6010 ,使用自己的电机需要修改PID参数,才能实现更好效果
|
||||
*/
|
||||
#include <SimpleFOC.h>
|
||||
#include "Command.h"
|
||||
#include <WiFi.h>
|
||||
#include <AsyncUDP.h> //引用以使用异步UDP
|
||||
#include <Kalman.h> // Source: https://github.com/TKJElectronics/KalmanFilter
|
||||
|
@ -65,6 +66,7 @@ BLDCDriver3PWM driver = BLDCDriver3PWM(32, 33, 25, 22);
|
|||
|
||||
|
||||
//命令设置
|
||||
Command command;
|
||||
double target_velocity = 0;
|
||||
double target_angle = 91;
|
||||
double target_voltage = 0;
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
#include "com.h"
|
||||
#include "Command.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
void Command::run(char* str){
|
||||
for(int i=0; i < call_count; i++){
|
||||
if(call_ids[i]){
|
||||
call_list[i](&str);
|
||||
if(isSentinel(call_ids[i],str)){ // case : call_ids = "T2" str = "T215.15"
|
||||
call_list[i](str+strlen(call_ids[i])); // get 15.15 input function
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -15,10 +18,11 @@ void Command::add(char* id, CommandCallback onCommand){
|
|||
void Command::scalar(float* value, char* user_cmd){
|
||||
*value = atof(user_cmd);
|
||||
}
|
||||
bool Commander::isSentinel(char* ch,char* str)
|
||||
bool Command::isSentinel(char* ch,char* str)
|
||||
{
|
||||
char s[strlen(ch)];
|
||||
char s[strlen(ch)+1];
|
||||
strncpy(s,str,strlen(ch));
|
||||
s[strlen(ch)] = '\0'; //strncpy need add end '\0'
|
||||
if(strcmp(ch, s) == 0)
|
||||
return true;
|
||||
else
|
|
@ -5,12 +5,12 @@ class Command
|
|||
public:
|
||||
void add(char* id , CommandCallback onCommand);
|
||||
void run(char* str);
|
||||
void Command::scalar(float* value, char* user_cmd);
|
||||
bool Commander::isSentinel(char* ch);
|
||||
void scalar(float* value, char* user_cmd);
|
||||
bool isSentinel(char* ch,char* str);
|
||||
private:
|
||||
// Subscribed command callback variables
|
||||
CommandCallback call_list[20];//!< array of command callback pointers - 20 is an arbitrary number
|
||||
char* call_ids[20]; //!< added callback commands
|
||||
int call_count = 0;//!< number callbacks that are subscribed
|
||||
int call_count;//!< number callbacks that are subscribed
|
||||
|
||||
}
|
||||
};
|
Binary file not shown.
|
@ -0,0 +1,31 @@
|
|||
# Project: ÏîÄ¿2
|
||||
# Makefile created by Dev-C++ 5.11
|
||||
|
||||
CPP = g++.exe
|
||||
CC = gcc.exe
|
||||
WINDRES = windres.exe
|
||||
OBJ = main.o Command.o
|
||||
LINKOBJ = main.o Command.o
|
||||
LIBS = -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib" -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib" -static-libgcc
|
||||
INCS = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include"
|
||||
CXXINCS = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++"
|
||||
BIN = ÏîÄ¿2.exe
|
||||
CXXFLAGS = $(CXXINCS)
|
||||
CFLAGS = $(INCS)
|
||||
RM = rm.exe -f
|
||||
|
||||
.PHONY: all all-before all-after clean clean-custom
|
||||
|
||||
all: all-before $(BIN) all-after
|
||||
|
||||
clean: clean-custom
|
||||
${RM} $(OBJ) $(BIN)
|
||||
|
||||
$(BIN): $(OBJ)
|
||||
$(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)
|
||||
|
||||
main.o: main.cpp
|
||||
$(CPP) -c main.cpp -o main.o $(CXXFLAGS)
|
||||
|
||||
Command.o: Command.cpp
|
||||
$(CPP) -c Command.cpp -o Command.o $(CXXFLAGS)
|
|
@ -1,7 +1,8 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "com.h"
|
||||
#include "Command.h"
|
||||
Command command;
|
||||
char buf[255];
|
||||
void wifi_print(char * s,double num)
|
||||
{
|
||||
|
@ -18,24 +19,8 @@ void re_command(float *num)
|
|||
{
|
||||
*num = *num + 1;
|
||||
}
|
||||
char* str = "abc23";
|
||||
char* cmd_id = "abc";
|
||||
//void doTarget(char* cmd) { command.scalar(&v, cmd); }
|
||||
main()
|
||||
{
|
||||
re_command(&v);
|
||||
char s[strlen(cmd_id)];
|
||||
|
||||
strncpy(s,str,strlen(cmd_id));
|
||||
printf("%s", s);
|
||||
if(strcmp(cmd_id, s) == 0)
|
||||
{
|
||||
printf("%f", v);
|
||||
v = atof(str+strlen(cmd_id));
|
||||
printf("%f", v);
|
||||
}
|
||||
|
||||
// char* da;
|
||||
// da = "123456";
|
||||
// if (da[0] == '2')
|
||||
|
||||
command.run();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "Command.h"
|
||||
Command command;
|
||||
char buf[255];
|
||||
void wifi_print(char * s,double num)
|
||||
{
|
||||
char str[255];
|
||||
char n[255];
|
||||
sprintf(n, "%.2f",num);
|
||||
strcpy(str,s);
|
||||
strcat(str, n);
|
||||
strcat(buf+strlen(buf), str);
|
||||
strcat(buf, ",");
|
||||
}
|
||||
float v = 0;
|
||||
float a = 0;
|
||||
void re_command(float *num)
|
||||
{
|
||||
*num = *num + 1;
|
||||
}
|
||||
void doTarget_v(char* cmd) { command.scalar(&v, cmd); }
|
||||
void doTarget_a(char* cmd) { command.scalar(&a, cmd); }
|
||||
main()
|
||||
{
|
||||
command.add("T", doTarget_v);
|
||||
command.add("A", doTarget_a);
|
||||
command.run("A2233");
|
||||
printf("%.2f",v);
|
||||
printf("%.2f",a);
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,8 @@
|
|||
[Editors]
|
||||
Order=0
|
||||
Focused=0
|
||||
[Editor_0]
|
||||
CursorCol=17
|
||||
CursorRow=14
|
||||
TopLine=8
|
||||
LeftChar=1
|
|
@ -0,0 +1,82 @@
|
|||
[Project]
|
||||
FileName=ÏîÄ¿2.dev
|
||||
Name=ÏîÄ¿2
|
||||
Type=1
|
||||
Ver=2
|
||||
ObjFiles=
|
||||
Includes=
|
||||
Libs=
|
||||
PrivateResource=
|
||||
ResourceIncludes=
|
||||
MakeIncludes=
|
||||
Compiler=
|
||||
CppCompiler=
|
||||
Linker=
|
||||
IsCpp=1
|
||||
Icon=
|
||||
ExeOutput=
|
||||
ObjectOutput=
|
||||
LogOutput=
|
||||
LogOutputEnabled=0
|
||||
OverrideOutput=0
|
||||
OverrideOutputName=
|
||||
HostApplication=
|
||||
UseCustomMakefile=0
|
||||
CustomMakefile=
|
||||
CommandLine=
|
||||
Folders=
|
||||
IncludeVersionInfo=0
|
||||
SupportXPThemes=0
|
||||
CompilerSet=0
|
||||
CompilerSettings=0000000000000000000000000
|
||||
UnitCount=3
|
||||
|
||||
[VersionInfo]
|
||||
Major=1
|
||||
Minor=0
|
||||
Release=0
|
||||
Build=0
|
||||
LanguageID=1033
|
||||
CharsetID=1252
|
||||
CompanyName=
|
||||
FileVersion=
|
||||
FileDescription=Developed using the Dev-C++ IDE
|
||||
InternalName=
|
||||
LegalCopyright=
|
||||
LegalTrademarks=
|
||||
OriginalFilename=
|
||||
ProductName=
|
||||
ProductVersion=
|
||||
AutoIncBuildNr=0
|
||||
SyncProduct=1
|
||||
|
||||
[Unit1]
|
||||
FileName=main.cpp
|
||||
CompileCpp=1
|
||||
Folder=
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit2]
|
||||
FileName=Command.cpp
|
||||
CompileCpp=1
|
||||
Folder=
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit3]
|
||||
FileName=Command.h
|
||||
CompileCpp=1
|
||||
Folder=
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
Binary file not shown.
|
@ -0,0 +1,8 @@
|
|||
[Editors]
|
||||
Order=0
|
||||
Focused=1
|
||||
[Editor_0]
|
||||
CursorCol=2
|
||||
CursorRow=20
|
||||
TopLine=12
|
||||
LeftChar=1
|
Loading…
Reference in New Issue