d
Revision 0:ee4e3ab4db45, committed 23 months ago
- Comitter:
- me33004m
- Date:
- Wed Nov 16 08:37:38 2022 +0000
- Commit message:
- abesshape
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Nov 16 08:37:38 2022 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sshape.cpp Wed Nov 16 08:37:38 2022 +0000
@@ -0,0 +1,51 @@
+#include "sshape.h"
+
+shape::shape(double time){
+ time_c = time;
+}
+
+int shape::pm(double num){
+ return (num>0)-(num<0);
+}
+double shape::start(){
+ start_m = clock();
+ return start_m;
+}
+double shape::shapeTime(double starttime){
+ return ((double)(clock() - starttime) / 100);
+}
+
+double shape::compute(double stickpoints,double starttime,double add){
+ shapeS_m = kasokudo(time_c,starttime,stickpoints,add);
+ if(pm(stickpoints - add_m)*shapeS_m <= pm(stickpoints - add)*stickpoints){
+ shapeS_m = kasokudo(time_c,starttime,stickpoints,add);
+ }else{
+ add_m = stickpoints;
+ return add_m;
+ }
+ return shapeS_m;
+}
+
+double shape::kasokudo(double time_s,double start_s,double points_s,double add_s){
+
+ if(points_s != 0){
+ if(points_s>add_s){
+ tmp = ((double)(clock() - start_s) / 100)/time_s;
+ shapeSpeed = tmp*tmp*pm(points_s)*fabs(points_s-add_s)*pm(points_s)+add_s;
+ }else{
+ tmp = ((double)(clock() - start_s) / 100)/time_s;
+ shapeSpeed = tmp*tmp*pm(points_s)*-fabs(points_s-add_s)*pm(points_s)+add_s;
+ }
+ }else{
+ if(points_s>add_s){
+ tmp = ((double)(clock() - start_s) / 100)/time_s;
+ shapeSpeed = tmp*tmp*-add_s + add_s;
+ }else{
+ tmp = ((double)(clock() - start_s) / 100)/time_s;
+ shapeSpeed = -tmp*tmp*add_s + add_s;
+ }
+ }
+
+ return shapeSpeed;
+
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sshape.h Wed Nov 16 08:37:38 2022 +0000
@@ -0,0 +1,68 @@
+#ifndef SSHAPE_H
+#define SSHAPE_H
+
+#include "stdio.h"
+#include "math.h"
+#include "time.h"
+#include "mbed.h"
+/* samplecode
+#include "stdio.h"
+#include "sshape.h"
+#include "mbed.h"
+#include "time.h"
+#include "stdlib.h"
+
+#define time 10
+
+shape sshape(time);
+
+ Serial pc(USBTX, USBRX, 115200);
+double pm(double num);
+
+int main(void){
+ double stickpoints = 10.0;
+ double add = 0;
+ while(1){
+ sshape.start();
+ double start = sshape.start();
+
+ while(1){
+ pc.printf("spend time : %4.2f ",sshape.shapeTime(start));
+ pc.printf("shape : %.2f Target : %.2f add : %.2f\r\n",sshape.compute(stickpoints,start,add),stickpoints,add);
+ if(pm(stickpoints-add)*sshape.compute(stickpoints,start,add) >= pm(stickpoints-add)*stickpoints){
+ add = sshape.compute(stickpoints,start,add);
+ pc.printf("aaaaaaaaaaaaaaddddddddddddd %f",add);
+ break;}
+ }
+ for(int i=0; i<10; i++){
+ pc.printf("%f",add);
+ }
+ stickpoints = rand() % 257- 128;;
+ }
+}
+double pm(double num){
+ return (num>0)-(num<0);
+}
+
+
+*/
+
+class shape {
+public:
+ shape(double time);
+ double compute(double stickpoints,double starttime,double add);
+ double start();
+ double shapeTime(double starttime);
+ double kasokudo(double time_s,double start_s,double points_s,double add_s);
+ int pm(double num);
+private:
+ double shapeS_m;
+ double add_m;
+ double time_tmp;
+ double tmp;
+ double time_c;
+ double shapeSpeed;
+ double time;
+ clock_t start_m;
+};
+#endif