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: AX-12A Dynamixel mbed iothub_client EthernetInterface NTPClient ConfigFile SDFileSystem iothub_amqp_transport mbed-rtos proton-c-mbed wolfSSL
RobotArmCfg.cpp
00001 // Copyright (c) Microsoft. All rights reserved. 00002 // Licensed under the MIT license. See LICENSE file in the project root for full license information. 00003 00004 #include "mbed.h" 00005 #include "SDFileSystem.h" 00006 #include "ConfigFile.h" 00007 00008 #include "RobotArmCfg.h" 00009 00010 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); //MOSI, MISO, SCLK, SSEL 00011 00012 ConfigFile cfg; 00013 00014 // connection string filled in from configuration file 00015 // if not using input.cfg configuration file specify connection string here 00016 // String containing IoT hub Hostname, Device Id & Device Key in the format: 00017 // "HostName=<host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>" 00018 char* connectionString = "[device connection string]"; 00019 00020 // specify joints in arm 00021 // if not using input.cfg configuration file specify joints here 00022 //static NodeCfg ArmJoints[NUMJOINTS] = { 00023 // { NT_AX12, 2 }, 00024 // { NT_AX12, 3 }, 00025 // { NT_AX12, 4 }, 00026 // { NT_AX12, 6 }, 00027 // { NT_AX12, 1 } 00028 //}; 00029 00030 // joints array filled in from configuration file 00031 NodeCfg ArmJoints[NUMJOINTS]; 00032 00033 // read config values from file input.cfg on SD card 00034 // example format of file is 00035 // JointType_0=AX12 00036 // JointType_1=AX12 00037 // JointType_2=AX12 00038 // JointType_3=AX12 00039 // JointType_4=AX12 00040 // JointId_0=2 00041 // JointId_1=3 00042 // JointId_2=4 00043 // JointId_3=6 00044 // JointId_4=1 00045 // IoTConnection=HostName=[device connection string] 00046 // 00047 bool ReadConfigValues() 00048 { 00049 char value[BUFSIZ]; 00050 bool rc = true; 00051 00052 printf("Reading config\r\n"); 00053 00054 /* Read a configuration file from a mbed. */ 00055 if (!cfg.read("/sd/input.cfg")) { 00056 // sometimes fails first time. Try again 00057 if (!cfg.read("/sd/input.cfg")) { 00058 printf("Failure to read a configuration file.\r\n"); 00059 rc = false; 00060 } 00061 } 00062 00063 /* Get configuration values. */ 00064 if (cfg.getValue("IoTConnection", &value[0], sizeof(value))) { 00065 int len = strlen(value) + 1; 00066 connectionString = (char*)malloc(len); 00067 strcpy(connectionString, value); 00068 } 00069 else 00070 { 00071 printf("Failure to read a configuration file value IoTConnection.\r\n"); 00072 rc = false; 00073 } 00074 00075 for (int ix = 0; ix < NUMJOINTS; ix++) 00076 { 00077 char key[20]; 00078 00079 sprintf(key, "JointType_%d", ix); 00080 if (cfg.getValue(key, &value[0], sizeof(value))) { 00081 ArmJoints[ix].JointType = NT_AX12; 00082 } 00083 else 00084 { 00085 printf("Failure to read a configuration file value %s.\r\n", key); 00086 rc = false; 00087 } 00088 sprintf(key, "JointId_%d", ix); 00089 if (cfg.getValue(key, &value[0], sizeof(value))) { 00090 ArmJoints[ix].JointId = atoi(value); 00091 } 00092 else 00093 { 00094 printf("Failure to read a configuration file value %s.\r\n", key); 00095 rc = false; 00096 } 00097 } 00098 00099 return rc; 00100 }
Generated on Tue Jul 12 2022 16:05:15 by
1.7.2