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.
Revision 4:0a12973cf24a, committed 2020-08-28
- Comitter:
- mfurukawa
- Date:
- Fri Aug 28 14:06:17 2020 +0000
- Parent:
- 3:1e1a29557d8e
- Commit message:
- confirmed pulse width changing via p26;
Changed in this revision
| jikken.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/jikken.cpp Fri Aug 28 08:49:45 2020 +0000
+++ b/jikken.cpp Fri Aug 28 14:06:17 2020 +0000
@@ -8,15 +8,9 @@
PwmOut servo4(p25);//θ4 pin
PwmOut servo5(p26);//θ5 pin
-//for plogram check
-DigitalOut led1(LED1);
-DigitalOut led2(LED2);
-DigitalOut led3(LED3);
-DigitalOut led4(LED4);
-
Serial pc(USBTX, USBRX);
#define SampleFreq 60 // [Hz]
-Ticker ticker;
+//Ticker ticker;
FILE* fp;
int cnt;
@@ -25,6 +19,7 @@
float aOut, bOut, cOut, dOut, eOut, fOut;//J123456 degree
int pw0, pw1, pw2, pw3, pw4, pw5;//Output Pulse Width
+float* pOut[6];
//degree to PulseWidth
int cal_input0(float arg) {
@@ -72,26 +67,16 @@
cal_pw();
send_servo();
}
-
-void move_attach()
-{
- led3=0.0;
- //fscanf(fp, "%f,%f,%f\n",&Out[i][0],&Out[i][1],&Out[i][2]);
- if(fp!=NULL or cnt<2548)
- fscanf(fp, "%f,%f,%f\n",&aOut,&bOut,&cOut);
- cnt++;
- led3=1.0;
- dOut = 0.0;
- eOut = 0.0;
- fOut = 0.0;
- move();
-}
int main(void)
{
- //pc.baud(115200);
- //pc.format(8, Serial::None, 1);
- //pc.printf("start\n");
- float w = 60.0;//========Control Frequency===========
+ //===============ボーレート=============
+ pc.baud(921600);
+ pc.format(8, Serial::None, 1);
+
+ char rbuf[4];
+
+ //========Control Frequency===========
+ float w = 60.0;
float PWMperiod = 1.0 / w;
servo0.period(PWMperiod);
@@ -100,43 +85,31 @@
servo3.period(PWMperiod);
servo4.period(PWMperiod);
servo5.period(PWMperiod);
-
- led4=1.0;
- //float Out[2548][3];
- led2=1.0;
+
+ // store pointer
+ pOut[0] = &aOut;
+ pOut[1] = &bOut;
+ pOut[2] = &cOut;
+ pOut[3] = &dOut;
+ pOut[4] = &eOut;
+ pOut[5] = &fOut;
+
+ while (1) {
+ //動かす関数
+ move();
+
+ if (pc.readable()) {
+ if (pc.getc() != '*') continue;
+ if (pc.getc() != '+') continue;
+ for (int i = 0; i < 6; i++) {
+ for (int b = 0; b < 4; b++)
+ rbuf[b] = pc.getc();
- char fname[] ="/local/xy14.csv";
- fp = fopen(fname, "r");
- if (fp == NULL)
- {
- led1 = 1.0;
- led2 = 1.0;
- led3 = 1.0;
- led4 = 1.0;
- //pc.printf("error\n");
+ // ( 4 bytes -> one float )
+ float const* f = reinterpret_cast<float const*>(rbuf);
+ *pOut[i] = *f;
+ }
+ }
+
}
- else
- {
- led3=1.0;
- //pc.printf("moving\n");
- cnt = 0;
- ticker.attach_us(move_attach, 1000000.0f/SampleFreq);
- //led2=1.0;
- /*for(i=0;i<2548;i++)
- {
- aOut = Out[i][0];
- bOut = Out[i][1];
- cOut = Out[i][2];
- dOut = 0.0;
- eOut = 0.0;
- fOut = 0.0;
- move();
- wait_ms(0.16);
- } */
- }
- led1=1.0;
- led2=1.0;
- led3=1.0;
- led4=1.0;
- return 0;
}
\ No newline at end of file