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.
Dependencies: mbed
Revision 0:a5b70e916def, committed 2019-02-07
- Comitter:
- tengtingtong
- Date:
- Thu Feb 07 13:33:31 2019 +0000
- Commit message:
- First commit
Changed in this revision
diff -r 000000000000 -r a5b70e916def libz_dynamixel.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libz_dynamixel.lib Thu Feb 07 13:33:31 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/Surrogate-Robot/code/libz_dynamixel/#c93069e41792
diff -r 000000000000 -r a5b70e916def main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Feb 07 13:33:31 2019 +0000
@@ -0,0 +1,74 @@
+#include "mbed.h"
+#include "Dynamixel.h"
+
+void getData();
+void RobotHeadControl(float x, float y, float z);
+int *SplitPos(char posString[]);
+
+Dynamixel motor(PA_15,PB_7,1000000);
+Serial device(D1, D0, 115200);
+
+char buffer[100];
+char ch;
+int index = 0;
+
+float X_axis, Y_axis, Z_axis;
+
+int main()
+{
+ device.attach(&getData);
+ while(1)
+ {
+ if(buffer[strlen(buffer)-1] == '/')
+ {
+ X_axis = SplitPos(buffer)[0];
+ Y_axis = SplitPos(buffer)[1];
+ Z_axis = SplitPos(buffer)[2];
+
+ RobotHeadControl(X_axis, Y_axis, Z_axis);
+
+ memset(buffer,0,sizeof(buffer));
+ index = 0;
+ }
+ }
+}
+
+void getData()
+{
+ ch = device.getc();
+ buffer[index] = ch;
+ index++;
+}
+
+void RobotHeadControl(float tilt, float pan, float swing)
+{
+ int speed = 400;
+
+ //Set position of the Dynamixel Motor (Motor1(Swing):ID12, Motor2(Pan):ID3, Motor3(Tilt):ID2)
+ tilt = ((240 + tilt)*1024)/300;
+ pan = ((150 + pan)*1024)/300;
+ swing = ((150 + swing)*1024)/300;
+
+ motor.setPosition(2, tilt, speed);
+ motor.setPosition(12, pan, speed);
+ motor.setPosition(3, swing, speed);
+}
+
+int *SplitPos(char posString[])
+{
+ int count = 0;
+ static int position[3];
+ char delim[] = "(),/";
+ char *ptr = strtok(posString, delim);
+
+
+ while (ptr != NULL)
+ {
+ //atoi is a function to convert string to int
+ position[count] = atoi(ptr);
+ count++;
+ ptr = strtok(NULL, delim);
+ }
+
+ return position;
+}
diff -r 000000000000 -r a5b70e916def mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Feb 07 13:33:31 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc \ No newline at end of file