From 0307d7bc5dea5ca2bd503e6f5c3dc3081c374c22 Mon Sep 17 00:00:00 2001 From: Kyle <43458322+kyle-stevens@users.noreply.github.com> Date: Thu, 18 Apr 2019 18:45:55 -0700 Subject: [PATCH 01/16] Add files via upload updated serial line code for pwm motor vals --- driverside/src/i2carduino/i2carduino.ino | 61 ++++++++++++++ driverside/src/i2ctemplateRosSubscriber.cpp | 93 +++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 driverside/src/i2carduino/i2carduino.ino create mode 100644 driverside/src/i2ctemplateRosSubscriber.cpp diff --git a/driverside/src/i2carduino/i2carduino.ino b/driverside/src/i2carduino/i2carduino.ino new file mode 100644 index 0000000..1151702 --- /dev/null +++ b/driverside/src/i2carduino/i2carduino.ino @@ -0,0 +1,61 @@ +#include + + +#define TCAADDR 0x04 + +int clockSpeed = 100000; +char myOutput[32] = {0}; +char sent[32] = {0}; + +void setup() { + digitalWrite(6, HIGH); + Wire.begin(0x04); + Wire.setClock(clockSpeed); + Wire.onReceive(receiveEvent); + Wire.onRequest(sendEvent); + Serial.begin(9600); + tcaselect(1); +} + +void loop() { + delay(600); + Serial.println(myOutput); +} + +void tcaselect(uint8_t i) { + if (i > 7) return; + Wire.beginTransmission(TCAADDR); + Wire.write(1 << i); + Wire.endTransmission(); +} + +/* + * Receive + */ +void receiveEvent() { + char c[32] = {0}; //this defines the overflow for the cpp master code + int count = 0; + while (0 < Wire.available()) { + c[count] = Wire.read(); + Serial.print(c[count]); + count++; + } + Serial.println(); + strncpy(myOutput, c, 32); + // send(c); +} + +/* + * Send + */ +void sendEvent() { + char sentMessage[32] = "Message_Sent_Alex";//whatever value you want to send goes here, max number of chars defined by array + //Wire.beginTransmission(0x40); + Serial.print("Sending signal:\t"); + Wire.write(sentMessage); + + Serial.print(sentMessage); + + Serial.println(); + //Wire.endTransmission(); +} diff --git a/driverside/src/i2ctemplateRosSubscriber.cpp b/driverside/src/i2ctemplateRosSubscriber.cpp new file mode 100644 index 0000000..423d88e --- /dev/null +++ b/driverside/src/i2ctemplateRosSubscriber.cpp @@ -0,0 +1,93 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +int addr1 = 0x04; //primary address //successive i2c devices +int addr2 = 0x40; //successive i2c devices +int file_i2c; //primary address +int file_i2c2; //successive addresses +int pwmVals[8]; +char *filename = (char*)"/dev/i2c-1"; +int i2c_slave_overflow = 32; + +void arrayCallback(const std_msgs::UInt16MultiArray::ConstPtr& array); + +bool writeStream(int file_i2c, string output) { //writes a single string, must be interconnected words, to the i2c file and subsequent addresses + if (output.length() <= i2c_slave_overflow) { + if (write(file_i2c, output.c_str(), output.length()) != output.length()) { + printf("\tFailed to write to the i2c bus.\n"); + } + } + else { + printf("\t\tinput too long |:| overflow bounds exceeded and message voided\n"); + } + return true; +} + +bool readStream(int file_i2c, char buf[]) { //reads a string from the i2c address and writes it to buf[], n must be length of expected message, otherwise there will be a filed read transaction + int n=32; //this should be the number of expected characters + if (read(file_i2c, buf, n) != n) { + printf("\ti2c read transaction |:| failed\n"); + } + else { + //buf[] should contains read bytes/words?? + printf("\t%s\n", buf); + } +} + +void convertTo3BitHex(int val[], char pwmValsHex[]){ + for(int i =0; i::const_iterator it = array->data.begin(); it != array->data.end(); ++it){ + pwmVals[i] = *it; + i++; + } + char hexVals[32]; + //add in the sending of values and the hex conversion here + return; +} + +int main() { + //Open i2c bus + if((file_i2c = open(filename, O_RDWR)) < 0) { + printf("\tFailed to open the i2c bus\n"); + } + if(ioctl(file_i2c, I2C_SLAVE, addr1) < 0) { + printf("\tFailed to acquire bus access and/or talk to slave.\n"); + } + string input; + + ros::init(argc, argv, "pwmSubscriber"); + ros::NodeHandle n; + ros::Subscriber subPWM = n.subscribe("arrayCallback"); + ros::spinOnce(); + //send data + while(1){ + cin >> input; + writeStream(file_i2c, input); + char buf[32]; + readStream(file_i2c, buf); + } + return 0; +} \ No newline at end of file From 6ebc5c8fac8fc9b19bdd77e9eb4bfd646dbe0826 Mon Sep 17 00:00:00 2001 From: Kyle <43458322+kyle-stevens@users.noreply.github.com> Date: Thu, 18 Apr 2019 18:46:32 -0700 Subject: [PATCH 02/16] Delete i2ctemplateRosSubscriber.cpp --- driverside/src/i2ctemplateRosSubscriber.cpp | 93 --------------------- 1 file changed, 93 deletions(-) delete mode 100644 driverside/src/i2ctemplateRosSubscriber.cpp diff --git a/driverside/src/i2ctemplateRosSubscriber.cpp b/driverside/src/i2ctemplateRosSubscriber.cpp deleted file mode 100644 index 423d88e..0000000 --- a/driverside/src/i2ctemplateRosSubscriber.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -int addr1 = 0x04; //primary address //successive i2c devices -int addr2 = 0x40; //successive i2c devices -int file_i2c; //primary address -int file_i2c2; //successive addresses -int pwmVals[8]; -char *filename = (char*)"/dev/i2c-1"; -int i2c_slave_overflow = 32; - -void arrayCallback(const std_msgs::UInt16MultiArray::ConstPtr& array); - -bool writeStream(int file_i2c, string output) { //writes a single string, must be interconnected words, to the i2c file and subsequent addresses - if (output.length() <= i2c_slave_overflow) { - if (write(file_i2c, output.c_str(), output.length()) != output.length()) { - printf("\tFailed to write to the i2c bus.\n"); - } - } - else { - printf("\t\tinput too long |:| overflow bounds exceeded and message voided\n"); - } - return true; -} - -bool readStream(int file_i2c, char buf[]) { //reads a string from the i2c address and writes it to buf[], n must be length of expected message, otherwise there will be a filed read transaction - int n=32; //this should be the number of expected characters - if (read(file_i2c, buf, n) != n) { - printf("\ti2c read transaction |:| failed\n"); - } - else { - //buf[] should contains read bytes/words?? - printf("\t%s\n", buf); - } -} - -void convertTo3BitHex(int val[], char pwmValsHex[]){ - for(int i =0; i::const_iterator it = array->data.begin(); it != array->data.end(); ++it){ - pwmVals[i] = *it; - i++; - } - char hexVals[32]; - //add in the sending of values and the hex conversion here - return; -} - -int main() { - //Open i2c bus - if((file_i2c = open(filename, O_RDWR)) < 0) { - printf("\tFailed to open the i2c bus\n"); - } - if(ioctl(file_i2c, I2C_SLAVE, addr1) < 0) { - printf("\tFailed to acquire bus access and/or talk to slave.\n"); - } - string input; - - ros::init(argc, argv, "pwmSubscriber"); - ros::NodeHandle n; - ros::Subscriber subPWM = n.subscribe("arrayCallback"); - ros::spinOnce(); - //send data - while(1){ - cin >> input; - writeStream(file_i2c, input); - char buf[32]; - readStream(file_i2c, buf); - } - return 0; -} \ No newline at end of file From 8e6f6241ba0426f7f8c3b53ee120e3ed7caddf23 Mon Sep 17 00:00:00 2001 From: Kyle <43458322+kyle-stevens@users.noreply.github.com> Date: Thu, 18 Apr 2019 18:46:42 -0700 Subject: [PATCH 03/16] Delete i2carduino.ino --- driverside/src/i2carduino/i2carduino.ino | 61 ------------------------ 1 file changed, 61 deletions(-) delete mode 100644 driverside/src/i2carduino/i2carduino.ino diff --git a/driverside/src/i2carduino/i2carduino.ino b/driverside/src/i2carduino/i2carduino.ino deleted file mode 100644 index 1151702..0000000 --- a/driverside/src/i2carduino/i2carduino.ino +++ /dev/null @@ -1,61 +0,0 @@ -#include - - -#define TCAADDR 0x04 - -int clockSpeed = 100000; -char myOutput[32] = {0}; -char sent[32] = {0}; - -void setup() { - digitalWrite(6, HIGH); - Wire.begin(0x04); - Wire.setClock(clockSpeed); - Wire.onReceive(receiveEvent); - Wire.onRequest(sendEvent); - Serial.begin(9600); - tcaselect(1); -} - -void loop() { - delay(600); - Serial.println(myOutput); -} - -void tcaselect(uint8_t i) { - if (i > 7) return; - Wire.beginTransmission(TCAADDR); - Wire.write(1 << i); - Wire.endTransmission(); -} - -/* - * Receive - */ -void receiveEvent() { - char c[32] = {0}; //this defines the overflow for the cpp master code - int count = 0; - while (0 < Wire.available()) { - c[count] = Wire.read(); - Serial.print(c[count]); - count++; - } - Serial.println(); - strncpy(myOutput, c, 32); - // send(c); -} - -/* - * Send - */ -void sendEvent() { - char sentMessage[32] = "Message_Sent_Alex";//whatever value you want to send goes here, max number of chars defined by array - //Wire.beginTransmission(0x40); - Serial.print("Sending signal:\t"); - Wire.write(sentMessage); - - Serial.print(sentMessage); - - Serial.println(); - //Wire.endTransmission(); -} From c898ff972309cf32032aa041195cdac019b1ef42 Mon Sep 17 00:00:00 2001 From: Kyle <43458322+kyle-stevens@users.noreply.github.com> Date: Thu, 18 Apr 2019 18:47:25 -0700 Subject: [PATCH 04/16] Add files via upload final commit for current set of serial line --- robotside/src/i2carduino/i2carduino.ino | 61 ++++++++++++++ robotside/src/i2ctemplateRosSubscriber.cpp | 93 ++++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 robotside/src/i2carduino/i2carduino.ino create mode 100644 robotside/src/i2ctemplateRosSubscriber.cpp diff --git a/robotside/src/i2carduino/i2carduino.ino b/robotside/src/i2carduino/i2carduino.ino new file mode 100644 index 0000000..1151702 --- /dev/null +++ b/robotside/src/i2carduino/i2carduino.ino @@ -0,0 +1,61 @@ +#include + + +#define TCAADDR 0x04 + +int clockSpeed = 100000; +char myOutput[32] = {0}; +char sent[32] = {0}; + +void setup() { + digitalWrite(6, HIGH); + Wire.begin(0x04); + Wire.setClock(clockSpeed); + Wire.onReceive(receiveEvent); + Wire.onRequest(sendEvent); + Serial.begin(9600); + tcaselect(1); +} + +void loop() { + delay(600); + Serial.println(myOutput); +} + +void tcaselect(uint8_t i) { + if (i > 7) return; + Wire.beginTransmission(TCAADDR); + Wire.write(1 << i); + Wire.endTransmission(); +} + +/* + * Receive + */ +void receiveEvent() { + char c[32] = {0}; //this defines the overflow for the cpp master code + int count = 0; + while (0 < Wire.available()) { + c[count] = Wire.read(); + Serial.print(c[count]); + count++; + } + Serial.println(); + strncpy(myOutput, c, 32); + // send(c); +} + +/* + * Send + */ +void sendEvent() { + char sentMessage[32] = "Message_Sent_Alex";//whatever value you want to send goes here, max number of chars defined by array + //Wire.beginTransmission(0x40); + Serial.print("Sending signal:\t"); + Wire.write(sentMessage); + + Serial.print(sentMessage); + + Serial.println(); + //Wire.endTransmission(); +} diff --git a/robotside/src/i2ctemplateRosSubscriber.cpp b/robotside/src/i2ctemplateRosSubscriber.cpp new file mode 100644 index 0000000..423d88e --- /dev/null +++ b/robotside/src/i2ctemplateRosSubscriber.cpp @@ -0,0 +1,93 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +int addr1 = 0x04; //primary address //successive i2c devices +int addr2 = 0x40; //successive i2c devices +int file_i2c; //primary address +int file_i2c2; //successive addresses +int pwmVals[8]; +char *filename = (char*)"/dev/i2c-1"; +int i2c_slave_overflow = 32; + +void arrayCallback(const std_msgs::UInt16MultiArray::ConstPtr& array); + +bool writeStream(int file_i2c, string output) { //writes a single string, must be interconnected words, to the i2c file and subsequent addresses + if (output.length() <= i2c_slave_overflow) { + if (write(file_i2c, output.c_str(), output.length()) != output.length()) { + printf("\tFailed to write to the i2c bus.\n"); + } + } + else { + printf("\t\tinput too long |:| overflow bounds exceeded and message voided\n"); + } + return true; +} + +bool readStream(int file_i2c, char buf[]) { //reads a string from the i2c address and writes it to buf[], n must be length of expected message, otherwise there will be a filed read transaction + int n=32; //this should be the number of expected characters + if (read(file_i2c, buf, n) != n) { + printf("\ti2c read transaction |:| failed\n"); + } + else { + //buf[] should contains read bytes/words?? + printf("\t%s\n", buf); + } +} + +void convertTo3BitHex(int val[], char pwmValsHex[]){ + for(int i =0; i::const_iterator it = array->data.begin(); it != array->data.end(); ++it){ + pwmVals[i] = *it; + i++; + } + char hexVals[32]; + //add in the sending of values and the hex conversion here + return; +} + +int main() { + //Open i2c bus + if((file_i2c = open(filename, O_RDWR)) < 0) { + printf("\tFailed to open the i2c bus\n"); + } + if(ioctl(file_i2c, I2C_SLAVE, addr1) < 0) { + printf("\tFailed to acquire bus access and/or talk to slave.\n"); + } + string input; + + ros::init(argc, argv, "pwmSubscriber"); + ros::NodeHandle n; + ros::Subscriber subPWM = n.subscribe("arrayCallback"); + ros::spinOnce(); + //send data + while(1){ + cin >> input; + writeStream(file_i2c, input); + char buf[32]; + readStream(file_i2c, buf); + } + return 0; +} \ No newline at end of file From 2640d0f5bdd99e8dbb68639820e89cbf3d964c4e Mon Sep 17 00:00:00 2001 From: Kyle <43458322+kyle-stevens@users.noreply.github.com> Date: Tue, 23 Apr 2019 18:52:46 -0700 Subject: [PATCH 05/16] Update i2ctemplateRosSubscriber.cpp stuff --- robotside/src/i2ctemplateRosSubscriber.cpp | 80 +++++++++++++++++----- 1 file changed, 63 insertions(+), 17 deletions(-) diff --git a/robotside/src/i2ctemplateRosSubscriber.cpp b/robotside/src/i2ctemplateRosSubscriber.cpp index 423d88e..abed107 100644 --- a/robotside/src/i2ctemplateRosSubscriber.cpp +++ b/robotside/src/i2ctemplateRosSubscriber.cpp @@ -11,6 +11,8 @@ #include #include +#include + using namespace std; int addr1 = 0x04; //primary address //successive i2c devices @@ -46,14 +48,51 @@ bool readStream(int file_i2c, char buf[]) { //reads a string from the i2c addres } } -void convertTo3BitHex(int val[], char pwmValsHex[]){ - for(int i =0; i>int input1; + string sinput1; + for (int i =0; i<8; i++){ + int valueOf = pwmVals[i]; + sinput1 = sinput1 + convertTo3BitHex(valueOf); + if(i<7){sinput1 = sinput1 + "~";} + } + writeStream (file_i2c, sinput1); + char buf2[32]; + readStream(file_i2c, buf); return; } @@ -76,18 +128,12 @@ int main() { if(ioctl(file_i2c, I2C_SLAVE, addr1) < 0) { printf("\tFailed to acquire bus access and/or talk to slave.\n"); } - string input; + ros::init(argc, argv, "pwmSubscriber"); ros::NodeHandle n; ros::Subscriber subPWM = n.subscribe("arrayCallback"); ros::spinOnce(); - //send data - while(1){ - cin >> input; - writeStream(file_i2c, input); - char buf[32]; - readStream(file_i2c, buf); - } + return 0; -} \ No newline at end of file +} From a8b32c9f997daee3d7250fb4a960cb97d75dd1db Mon Sep 17 00:00:00 2001 From: Kyle <43458322+kyle-stevens@users.noreply.github.com> Date: Mon, 6 May 2019 11:49:12 -0700 Subject: [PATCH 06/16] code is now obsolete, new code being uploaded with improvements and further enhancements --- robotside/src/i2ctemplateRosSubscriber.cpp | 139 --------------------- 1 file changed, 139 deletions(-) delete mode 100644 robotside/src/i2ctemplateRosSubscriber.cpp diff --git a/robotside/src/i2ctemplateRosSubscriber.cpp b/robotside/src/i2ctemplateRosSubscriber.cpp deleted file mode 100644 index abed107..0000000 --- a/robotside/src/i2ctemplateRosSubscriber.cpp +++ /dev/null @@ -1,139 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace std; - -int addr1 = 0x04; //primary address //successive i2c devices -int addr2 = 0x40; //successive i2c devices -int file_i2c; //primary address -int file_i2c2; //successive addresses -int pwmVals[8]; -char *filename = (char*)"/dev/i2c-1"; -int i2c_slave_overflow = 32; - -void arrayCallback(const std_msgs::UInt16MultiArray::ConstPtr& array); - -bool writeStream(int file_i2c, string output) { //writes a single string, must be interconnected words, to the i2c file and subsequent addresses - if (output.length() <= i2c_slave_overflow) { - if (write(file_i2c, output.c_str(), output.length()) != output.length()) { - printf("\tFailed to write to the i2c bus.\n"); - } - } - else { - printf("\t\tinput too long |:| overflow bounds exceeded and message voided\n"); - } - return true; -} - -bool readStream(int file_i2c, char buf[]) { //reads a string from the i2c address and writes it to buf[], n must be length of expected message, otherwise there will be a filed read transaction - int n=32; //this should be the number of expected characters - if (read(file_i2c, buf, n) != n) { - printf("\ti2c read transaction |:| failed\n"); - } - else { - //buf[] should contains read bytes/words?? - printf("\t%s\n", buf); - } -} - -string intToHexDig(int value) { - string cHex; - if (value == 15) { - cHex = 'f'; - } - else if (value == 14) { - cHex = 'e'; - } - else if (value == 13) { - cHex = 'd'; - } - else if (value == 12) { - cHex = 'c'; - } - else if (value == 11) { - cHex = 'b'; - } - else if (value == 10) { - cHex = 'a'; - } - else { - cHex = to_string(value); - } - - return cHex; -} - -string convertTo3BitHex(int numOfBits, int decimal) { - string converted; - int firstChar = (int)(decimal/ (16 * 16)); - int firstRemainder = (int)(decimal % (16 * 16)); - int secondChar = (int)(firstRemainder / (16)); - int secondRemainder = (int)(firstRemainder % (16)); - int thirdChar = secondRemainder; - string cfirstChar, csecondChar, cthirdChar; - cfirstChar = intToHexDig(firstChar); - csecondChar = intToHexDig(secondChar); - cthirdChar = intToHexDig(thirdChar); - - converted = converted + cfirstChar; - converted = converted + csecondChar; - converted = converted + cthirdChar; - cout << converted << endl; - cout << "done"<::const_iterator it = array->data.begin(); it != array->data.end(); ++it){ - pwmVals[i] = *it; - i++; - } - char hexVals[32]; - //add in the sending of values and the hex conversion here - //send data - string input; - - cin>>int input1; - string sinput1; - for (int i =0; i<8; i++){ - int valueOf = pwmVals[i]; - sinput1 = sinput1 + convertTo3BitHex(valueOf); - if(i<7){sinput1 = sinput1 + "~";} - } - writeStream (file_i2c, sinput1); - char buf2[32]; - readStream(file_i2c, buf); - return; -} - -int main() { - //Open i2c bus - if((file_i2c = open(filename, O_RDWR)) < 0) { - printf("\tFailed to open the i2c bus\n"); - } - if(ioctl(file_i2c, I2C_SLAVE, addr1) < 0) { - printf("\tFailed to acquire bus access and/or talk to slave.\n"); - } - - - ros::init(argc, argv, "pwmSubscriber"); - ros::NodeHandle n; - ros::Subscriber subPWM = n.subscribe("arrayCallback"); - ros::spinOnce(); - - return 0; -} From 46f03f86e27a4bb047592bc71e491a26b6772b46 Mon Sep 17 00:00:00 2001 From: Kyle <43458322+kyle-stevens@users.noreply.github.com> Date: Mon, 6 May 2019 11:49:51 -0700 Subject: [PATCH 07/16] Add files via upload --- robotside/src/CMakeLists.txt | 37 +++++ robotside/src/hexConverter.cpp | 225 +++++++++++++++++++++++++++++++ robotside/src/hexConverterv2.cpp | 116 ++++++++++++++++ robotside/src/subber.cpp | 50 +++++++ robotside/src/tester.cpp | 42 ++++++ 5 files changed, 470 insertions(+) create mode 100644 robotside/src/CMakeLists.txt create mode 100644 robotside/src/hexConverter.cpp create mode 100644 robotside/src/hexConverterv2.cpp create mode 100644 robotside/src/subber.cpp create mode 100644 robotside/src/tester.cpp diff --git a/robotside/src/CMakeLists.txt b/robotside/src/CMakeLists.txt new file mode 100644 index 0000000..acd08ec --- /dev/null +++ b/robotside/src/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 2.8.3) +project(cpp_i2c_test) + +## Find catkin and any catkin packages +find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs genmsg) + +## Declare ROS messages and services +##add_message_files(FILES Num.msg) +##add_service_files(FILES AddTwoInts.srv) + +## Generate added messages and services +generate_messages(DEPENDENCIES std_msgs) + +## Declare a catkin package +catkin_package() + +## Build talker and listener +include_directories(include ${catkin_INCLUDE_DIRS}) + +add_executable(subber src/subber.cpp) +target_link_libraries(subber ${catkin_LIBRARIES}) +add_dependencies(subber cpp_i2c_test_generate_messages_cpp) + +##unit testing for ros usage +add_executable(tester src/tester.cpp) +target_link_libraries(tester ${catkin_LIBRARIES}) +add_dependencies(tester cpp_i2c_test_generate_messages_cpp) + +##testing conversion and ros cycling +add_executable(hexConverter src/hexConverter.cpp) +target_link_libraries(hexConverter ${catkin_LIBRARIES}) +add_dependencies(hexConverter cpp_i2c_test_generate_messages_cpp) + +##implementation of ros with i2c commands and conversions -- needs testing still +add_executable(hexConverterv2 src/hexConverterv2.cpp) +target_link_libraries(hexConverterv2 ${catkin_LIBRARIES}) +add_dependencies(hexConverterv2 cpp_i2c_test_generate_messages_cpp) diff --git a/robotside/src/hexConverter.cpp b/robotside/src/hexConverter.cpp new file mode 100644 index 0000000..68b2ad2 --- /dev/null +++ b/robotside/src/hexConverter.cpp @@ -0,0 +1,225 @@ +/* +#include +#include +#include +#include + +#include "ros/ros.h" + +#include "std_msgs/MultiArrayLayout.h" +#include "std_msgs/MultiArrayDimension.h" +#include "std_msgs/UInt16MultiArray.h" + +int Arr[8]; +void arrayCallback(const std_msgs::UInt16MultiArray::ConstPtr& array); + +int main(int argc, char **argv) +{ + + ros::init(argc, argv, "arraySubscriber"); + + ros::NodeHandle n; + + ros::Subscriber sub3 = n.subscribe("array", 1, arrayCallback); + while (ros::ok()) + { + ros::spinOnce(); + + for(int j = 1; j < 8; j++) + { + printf("%d, ", Arr[j]); + } + + printf("\n"); + + } + return 0; +} + +void arrayCallback(const std_msgs::UInt16MultiArray::ConstPtr& array) +{ + + int i = 0; + // print all the remaining numbers + for(std::vector::const_iterator it = array->data.begin(); it != array->data.end(); it++) + { + Arr[i] = *it; + i++; + } + + return; +} +*/ + + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + +using namespace std; + +int addr1 = 0x04; //primary address //successive i2c devices +int addr2 = 0x40; //successive i2c devices +int file_i2c; //primary address +int file_i2c2; //successive addresses +int pwmVals[8]; +char *filename = (char*)"/dev/i2c-1"; +int i2c_slave_overflow = 32; + +void arrayCallback(const std_msgs::UInt16MultiArray::ConstPtr& array); + +bool writeStream(int file_i2c, string output) { //writes a single string, must be interconnected words, to the i2c file and subsequent addresses + if (output.length() <= i2c_slave_overflow) { + if (write(file_i2c, output.c_str(), output.length()) != output.length()) { + printf("\tFailed to write to the i2c bus.\n"); + } + } + else { + printf("\t\tinput too long |:| overflow bounds exceeded and message voided\n"); + } + return true; +} + +bool readStream(int file_i2c, char buf[]) { //reads a string from the i2c address and writes it to buf[], n must be length of expected message, otherwise there will be a filed read transaction + int n=32; //this should be the number of expected characters + if (read(file_i2c, buf, n) != n) { + printf("\ti2c read transaction |:| failed\n"); + } + else { + //buf[] should contains read bytes/words?? + printf("\t%s\n", buf); + } +} + +string intToHexDig(int value) { + string cHex; + if (value == 15) { + cHex = 'f'; + } + else if (value == 14) { + cHex = 'e'; + } + else if (value == 13) { + cHex = 'd'; + } + else if (value == 12) { + cHex = 'c'; + } + else if (value == 11) { + cHex = 'b'; + } + else if (value == 10) { + cHex = 'a'; + } + else if (value == 9) { + cHex = '9'; + } + else if (value == 8) { + cHex = '8'; + } + else if (value == 7) { + cHex = '7'; + } + else if (value == 6) { + cHex = '6'; + } + else if (value == 5) { + cHex = '5'; + } + else if (value == 4) { + cHex = '4'; + } + else if (value == 3) { + cHex = '3'; + } + else if (value == 2) { + cHex = '2'; + } + else if (value == 1) { + cHex = '1'; + } + else if (value == 0) { + cHex = '0'; + } + + return cHex; +} + +string convertTo3BitHex(int decimal) { + string converted; + int firstChar = (int)(decimal/ (16 * 16)); + int firstRemainder = (int)(decimal % (16 * 16)); + int secondChar = (int)(firstRemainder / (16)); + int secondRemainder = (int)(firstRemainder % (16)); + int thirdChar = secondRemainder; + string cfirstChar, csecondChar, cthirdChar; + cfirstChar = intToHexDig(firstChar); + csecondChar = intToHexDig(secondChar); + cthirdChar = intToHexDig(thirdChar); + + converted = converted + cfirstChar; + converted = converted + csecondChar; + converted = converted + cthirdChar; +// cout << converted << endl; +// cout << "done"<::const_iterator it = array->data.begin(); it != array->data.end(); ++it){ + pwmVals[i] = *it; + i++; + } + char hexVals[32]; + //add in the sending of values and the hex conversion here + //send data + string sinput1; + for (int i =0; i<8; i++){ + int valueOf = pwmVals[i]; + sinput1 = sinput1 + convertTo3BitHex(valueOf); + if(i<7){sinput1 = sinput1 + "~";} + } + cout << sinput1; + //writeStream (file_i2c, sinput1); + char buf2[32]; + //readStream(file_i2c, buf); + return; +} diff --git a/robotside/src/hexConverterv2.cpp b/robotside/src/hexConverterv2.cpp new file mode 100644 index 0000000..c1949a6 --- /dev/null +++ b/robotside/src/hexConverterv2.cpp @@ -0,0 +1,116 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +int addr1 = 0x04; +int file_i2c; +int i2c_slave_overflow = 32; +int pwmVals[8]; +char *filename = (char*)"/dev/i2c-1"; + +void arrayCallback(const std_msgs::UInt16MultiArray::ConstPtr& array); + +bool writeStream(int file_i2c, string output) { + if (output.length() <= i2c_slave_overflow) { + if (write(file_i2c, output.c_str(), output.length()) != output.length()) { + printf("\tFailed to write to the i2c bus.\n"); + } + } + else { + printf("\t\tinput too long |:| overflow bounds exceeded and message voided\n"); + } + return true; +} + +bool readStream(int file_i2c, char buf[]) { + int n=32; + if (read(file_i2c, buf, n) != n) { + printf("\ti2c read transaction |:| failed\n"); + } + else { + printf("\t%s\n", buf); + } +} + +string intToHexDig(int value) { + string cHex;//this block can be written as a case statement, but im lazy + if (value == 15) {cHex = 'f';} + else if (value == 14) {cHex = 'e';} + else if (value == 13) {cHex = 'd';} + else if (value == 12) {cHex = 'c';} + else if (value == 11) {cHex = 'b';} + else if (value == 10) {cHex = 'a';} + else if (value == 9) {cHex = '9';} + else if (value == 8) {cHex = '8';} + else if (value == 7) {cHex = '7';} + else if (value == 6) {cHex = '6';} + else if (value == 5) {cHex = '5';} + else if (value == 4) {cHex = '4';} + else if (value == 3) {cHex = '3';} + else if (value == 2) {cHex = '2';} + else if (value == 1) {cHex = '1';} + else if (value == 0) {cHex = '0';} + return cHex; +} + +string convertTo3BitHex(int decimal) { + string converted; + + int firstChar = (int)(decimal/ (16 * 16)); + int firstRemainder = (int)(decimal % (16 * 16)); + int secondChar = (int)(firstRemainder / (16)); + int secondRemainder = (int)(firstRemainder % (16)); + int thirdChar = secondRemainder; + + string cfirstChar, csecondChar, cthirdChar; + cfirstChar = intToHexDig(firstChar); + csecondChar = intToHexDig(secondChar); + cthirdChar = intToHexDig(thirdChar); + + converted = converted + cfirstChar + csecondChar + cthirdChar; + return converted; +} + +int main(int argc, char **argv) { + //Open i2c bus + if((file_i2c = open(filename, O_RDWR)) < 0) {printf("\tFailed to open the i2c bus\n");} + if(ioctl(file_i2c, I2C_SLAVE, addr1) < 0) {printf("\tFailed to acquire bus access and/or talk to slave.\n");} + + //ros initialization + ros::init(argc, argv, "pwmSubscriber"); + ros::NodeHandle n; + ros::Subscriber subPWM = n.subscribe("array",1,arrayCallback); + while(ros::ok()){ros::spinOnce();} + return 0; +} + +void arrayCallback(const std_msgs::UInt16MultiArray::ConstPtr& array){ + int i = 0; + for(std::vector::const_iterator it = array->data.begin(); it != array->data.end(); ++it){ + pwmVals[i] = *it; + i++; + } + char hexVals[32]; + string sinput1; //contains converted hex values + for (int i =0; i<8; i++){ + int valueOf = pwmVals[i]; + sinput1 = sinput1 + convertTo3BitHex(valueOf); + if(i<7){sinput1 = sinput1 + "~";} + } + cout << sinput1; + writeStream (file_i2c, sinput1); + char buf2[32]; + readStream(file_i2c, buf); + return; +} diff --git a/robotside/src/subber.cpp b/robotside/src/subber.cpp new file mode 100644 index 0000000..56bac95 --- /dev/null +++ b/robotside/src/subber.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include + +#include "ros/ros.h" + +#include "std_msgs/MultiArrayLayout.h" +#include "std_msgs/MultiArrayDimension.h" +#include "std_msgs/UInt16MultiArray.h" + +int Arr[8]; +void arrayCallback(const std_msgs::UInt16MultiArray::ConstPtr& array); + +int main(int argc, char **argv) +{ + + ros::init(argc, argv, "arraySubscriber"); + + ros::NodeHandle n; + + ros::Subscriber sub3 = n.subscribe("array", 1, arrayCallback); + while (ros::ok()) + { + ros::spinOnce(); + + for(int j = 1; j < 8; j++) + { + printf("%d, ", Arr[j]); + } + + printf("\n"); + + } + return 0; +} + +void arrayCallback(const std_msgs::UInt16MultiArray::ConstPtr& array) +{ + + int i = 0; + // print all the remaining numbers + for(std::vector::const_iterator it = array->data.begin(); it != array->data.end(); it++) + { + Arr[i] = *it; + i++; + } + + return; +} diff --git a/robotside/src/tester.cpp b/robotside/src/tester.cpp new file mode 100644 index 0000000..01720ce --- /dev/null +++ b/robotside/src/tester.cpp @@ -0,0 +1,42 @@ +#include +#include + +#include "ros/ros.h" + +#include "std_msgs/MultiArrayLayout.h" +#include "std_msgs/MultiArrayDimension.h" + +#include "std_msgs/UInt16MultiArray.h" + +int main(int argc, char **argv) +{ + + + ros::init(argc, argv, "arrayPublisher"); + + ros::NodeHandle n; + + ros::Publisher pub = n.advertise("array", 1); + + while (ros::ok()) + { + std_msgs::UInt16MultiArray array; + //Clear array + array.data.clear(); + //for loop, pushing data in the size of the array + for (int i = 0; i < 8; i++) + { + //assign array a random number between 0 and 255. + array.data.push_back(rand() % 255); + } + //Publish array + pub.publish(array); + //Let the world know + ROS_INFO("I published something!"); + //Do this. + ros::spinOnce(); + //Added a delay so not to spam + sleep(2); + } + +} From f41bf3fb9c2d8038f1c51f6bfd026e09a1d1ea5a Mon Sep 17 00:00:00 2001 From: Kyle <43458322+kyle-stevens@users.noreply.github.com> Date: Thu, 9 May 2019 15:14:04 -0700 Subject: [PATCH 08/16] Delete i2carduino.ino --- robotside/src/i2carduino/i2carduino.ino | 61 ------------------------- 1 file changed, 61 deletions(-) delete mode 100644 robotside/src/i2carduino/i2carduino.ino diff --git a/robotside/src/i2carduino/i2carduino.ino b/robotside/src/i2carduino/i2carduino.ino deleted file mode 100644 index 1151702..0000000 --- a/robotside/src/i2carduino/i2carduino.ino +++ /dev/null @@ -1,61 +0,0 @@ -#include - - -#define TCAADDR 0x04 - -int clockSpeed = 100000; -char myOutput[32] = {0}; -char sent[32] = {0}; - -void setup() { - digitalWrite(6, HIGH); - Wire.begin(0x04); - Wire.setClock(clockSpeed); - Wire.onReceive(receiveEvent); - Wire.onRequest(sendEvent); - Serial.begin(9600); - tcaselect(1); -} - -void loop() { - delay(600); - Serial.println(myOutput); -} - -void tcaselect(uint8_t i) { - if (i > 7) return; - Wire.beginTransmission(TCAADDR); - Wire.write(1 << i); - Wire.endTransmission(); -} - -/* - * Receive - */ -void receiveEvent() { - char c[32] = {0}; //this defines the overflow for the cpp master code - int count = 0; - while (0 < Wire.available()) { - c[count] = Wire.read(); - Serial.print(c[count]); - count++; - } - Serial.println(); - strncpy(myOutput, c, 32); - // send(c); -} - -/* - * Send - */ -void sendEvent() { - char sentMessage[32] = "Message_Sent_Alex";//whatever value you want to send goes here, max number of chars defined by array - //Wire.beginTransmission(0x40); - Serial.print("Sending signal:\t"); - Wire.write(sentMessage); - - Serial.print(sentMessage); - - Serial.println(); - //Wire.endTransmission(); -} From 8655427be70c6ae74e2066319b044d850ec8eed8 Mon Sep 17 00:00:00 2001 From: Kyle <43458322+kyle-stevens@users.noreply.github.com> Date: Thu, 9 May 2019 15:14:16 -0700 Subject: [PATCH 09/16] Delete CMakeLists.txt --- robotside/src/CMakeLists.txt | 37 ------------------------------------ 1 file changed, 37 deletions(-) delete mode 100644 robotside/src/CMakeLists.txt diff --git a/robotside/src/CMakeLists.txt b/robotside/src/CMakeLists.txt deleted file mode 100644 index acd08ec..0000000 --- a/robotside/src/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -cmake_minimum_required(VERSION 2.8.3) -project(cpp_i2c_test) - -## Find catkin and any catkin packages -find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs genmsg) - -## Declare ROS messages and services -##add_message_files(FILES Num.msg) -##add_service_files(FILES AddTwoInts.srv) - -## Generate added messages and services -generate_messages(DEPENDENCIES std_msgs) - -## Declare a catkin package -catkin_package() - -## Build talker and listener -include_directories(include ${catkin_INCLUDE_DIRS}) - -add_executable(subber src/subber.cpp) -target_link_libraries(subber ${catkin_LIBRARIES}) -add_dependencies(subber cpp_i2c_test_generate_messages_cpp) - -##unit testing for ros usage -add_executable(tester src/tester.cpp) -target_link_libraries(tester ${catkin_LIBRARIES}) -add_dependencies(tester cpp_i2c_test_generate_messages_cpp) - -##testing conversion and ros cycling -add_executable(hexConverter src/hexConverter.cpp) -target_link_libraries(hexConverter ${catkin_LIBRARIES}) -add_dependencies(hexConverter cpp_i2c_test_generate_messages_cpp) - -##implementation of ros with i2c commands and conversions -- needs testing still -add_executable(hexConverterv2 src/hexConverterv2.cpp) -target_link_libraries(hexConverterv2 ${catkin_LIBRARIES}) -add_dependencies(hexConverterv2 cpp_i2c_test_generate_messages_cpp) From c3086329a2116aea8cfde5f3ef155a1a53984325 Mon Sep 17 00:00:00 2001 From: Kyle <43458322+kyle-stevens@users.noreply.github.com> Date: Thu, 9 May 2019 15:14:33 -0700 Subject: [PATCH 10/16] Delete hexConverter.cpp --- robotside/src/hexConverter.cpp | 225 --------------------------------- 1 file changed, 225 deletions(-) delete mode 100644 robotside/src/hexConverter.cpp diff --git a/robotside/src/hexConverter.cpp b/robotside/src/hexConverter.cpp deleted file mode 100644 index 68b2ad2..0000000 --- a/robotside/src/hexConverter.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/* -#include -#include -#include -#include - -#include "ros/ros.h" - -#include "std_msgs/MultiArrayLayout.h" -#include "std_msgs/MultiArrayDimension.h" -#include "std_msgs/UInt16MultiArray.h" - -int Arr[8]; -void arrayCallback(const std_msgs::UInt16MultiArray::ConstPtr& array); - -int main(int argc, char **argv) -{ - - ros::init(argc, argv, "arraySubscriber"); - - ros::NodeHandle n; - - ros::Subscriber sub3 = n.subscribe("array", 1, arrayCallback); - while (ros::ok()) - { - ros::spinOnce(); - - for(int j = 1; j < 8; j++) - { - printf("%d, ", Arr[j]); - } - - printf("\n"); - - } - return 0; -} - -void arrayCallback(const std_msgs::UInt16MultiArray::ConstPtr& array) -{ - - int i = 0; - // print all the remaining numbers - for(std::vector::const_iterator it = array->data.begin(); it != array->data.end(); it++) - { - Arr[i] = *it; - i++; - } - - return; -} -*/ - - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - - -using namespace std; - -int addr1 = 0x04; //primary address //successive i2c devices -int addr2 = 0x40; //successive i2c devices -int file_i2c; //primary address -int file_i2c2; //successive addresses -int pwmVals[8]; -char *filename = (char*)"/dev/i2c-1"; -int i2c_slave_overflow = 32; - -void arrayCallback(const std_msgs::UInt16MultiArray::ConstPtr& array); - -bool writeStream(int file_i2c, string output) { //writes a single string, must be interconnected words, to the i2c file and subsequent addresses - if (output.length() <= i2c_slave_overflow) { - if (write(file_i2c, output.c_str(), output.length()) != output.length()) { - printf("\tFailed to write to the i2c bus.\n"); - } - } - else { - printf("\t\tinput too long |:| overflow bounds exceeded and message voided\n"); - } - return true; -} - -bool readStream(int file_i2c, char buf[]) { //reads a string from the i2c address and writes it to buf[], n must be length of expected message, otherwise there will be a filed read transaction - int n=32; //this should be the number of expected characters - if (read(file_i2c, buf, n) != n) { - printf("\ti2c read transaction |:| failed\n"); - } - else { - //buf[] should contains read bytes/words?? - printf("\t%s\n", buf); - } -} - -string intToHexDig(int value) { - string cHex; - if (value == 15) { - cHex = 'f'; - } - else if (value == 14) { - cHex = 'e'; - } - else if (value == 13) { - cHex = 'd'; - } - else if (value == 12) { - cHex = 'c'; - } - else if (value == 11) { - cHex = 'b'; - } - else if (value == 10) { - cHex = 'a'; - } - else if (value == 9) { - cHex = '9'; - } - else if (value == 8) { - cHex = '8'; - } - else if (value == 7) { - cHex = '7'; - } - else if (value == 6) { - cHex = '6'; - } - else if (value == 5) { - cHex = '5'; - } - else if (value == 4) { - cHex = '4'; - } - else if (value == 3) { - cHex = '3'; - } - else if (value == 2) { - cHex = '2'; - } - else if (value == 1) { - cHex = '1'; - } - else if (value == 0) { - cHex = '0'; - } - - return cHex; -} - -string convertTo3BitHex(int decimal) { - string converted; - int firstChar = (int)(decimal/ (16 * 16)); - int firstRemainder = (int)(decimal % (16 * 16)); - int secondChar = (int)(firstRemainder / (16)); - int secondRemainder = (int)(firstRemainder % (16)); - int thirdChar = secondRemainder; - string cfirstChar, csecondChar, cthirdChar; - cfirstChar = intToHexDig(firstChar); - csecondChar = intToHexDig(secondChar); - cthirdChar = intToHexDig(thirdChar); - - converted = converted + cfirstChar; - converted = converted + csecondChar; - converted = converted + cthirdChar; -// cout << converted << endl; -// cout << "done"<::const_iterator it = array->data.begin(); it != array->data.end(); ++it){ - pwmVals[i] = *it; - i++; - } - char hexVals[32]; - //add in the sending of values and the hex conversion here - //send data - string sinput1; - for (int i =0; i<8; i++){ - int valueOf = pwmVals[i]; - sinput1 = sinput1 + convertTo3BitHex(valueOf); - if(i<7){sinput1 = sinput1 + "~";} - } - cout << sinput1; - //writeStream (file_i2c, sinput1); - char buf2[32]; - //readStream(file_i2c, buf); - return; -} From 0bd8ddd2c02b7a18a579401e2e0b7ca8193d5d64 Mon Sep 17 00:00:00 2001 From: Kyle <43458322+kyle-stevens@users.noreply.github.com> Date: Thu, 9 May 2019 15:14:42 -0700 Subject: [PATCH 11/16] Delete hexConverterv2.cpp --- robotside/src/hexConverterv2.cpp | 116 ------------------------------- 1 file changed, 116 deletions(-) delete mode 100644 robotside/src/hexConverterv2.cpp diff --git a/robotside/src/hexConverterv2.cpp b/robotside/src/hexConverterv2.cpp deleted file mode 100644 index c1949a6..0000000 --- a/robotside/src/hexConverterv2.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -int addr1 = 0x04; -int file_i2c; -int i2c_slave_overflow = 32; -int pwmVals[8]; -char *filename = (char*)"/dev/i2c-1"; - -void arrayCallback(const std_msgs::UInt16MultiArray::ConstPtr& array); - -bool writeStream(int file_i2c, string output) { - if (output.length() <= i2c_slave_overflow) { - if (write(file_i2c, output.c_str(), output.length()) != output.length()) { - printf("\tFailed to write to the i2c bus.\n"); - } - } - else { - printf("\t\tinput too long |:| overflow bounds exceeded and message voided\n"); - } - return true; -} - -bool readStream(int file_i2c, char buf[]) { - int n=32; - if (read(file_i2c, buf, n) != n) { - printf("\ti2c read transaction |:| failed\n"); - } - else { - printf("\t%s\n", buf); - } -} - -string intToHexDig(int value) { - string cHex;//this block can be written as a case statement, but im lazy - if (value == 15) {cHex = 'f';} - else if (value == 14) {cHex = 'e';} - else if (value == 13) {cHex = 'd';} - else if (value == 12) {cHex = 'c';} - else if (value == 11) {cHex = 'b';} - else if (value == 10) {cHex = 'a';} - else if (value == 9) {cHex = '9';} - else if (value == 8) {cHex = '8';} - else if (value == 7) {cHex = '7';} - else if (value == 6) {cHex = '6';} - else if (value == 5) {cHex = '5';} - else if (value == 4) {cHex = '4';} - else if (value == 3) {cHex = '3';} - else if (value == 2) {cHex = '2';} - else if (value == 1) {cHex = '1';} - else if (value == 0) {cHex = '0';} - return cHex; -} - -string convertTo3BitHex(int decimal) { - string converted; - - int firstChar = (int)(decimal/ (16 * 16)); - int firstRemainder = (int)(decimal % (16 * 16)); - int secondChar = (int)(firstRemainder / (16)); - int secondRemainder = (int)(firstRemainder % (16)); - int thirdChar = secondRemainder; - - string cfirstChar, csecondChar, cthirdChar; - cfirstChar = intToHexDig(firstChar); - csecondChar = intToHexDig(secondChar); - cthirdChar = intToHexDig(thirdChar); - - converted = converted + cfirstChar + csecondChar + cthirdChar; - return converted; -} - -int main(int argc, char **argv) { - //Open i2c bus - if((file_i2c = open(filename, O_RDWR)) < 0) {printf("\tFailed to open the i2c bus\n");} - if(ioctl(file_i2c, I2C_SLAVE, addr1) < 0) {printf("\tFailed to acquire bus access and/or talk to slave.\n");} - - //ros initialization - ros::init(argc, argv, "pwmSubscriber"); - ros::NodeHandle n; - ros::Subscriber subPWM = n.subscribe("array",1,arrayCallback); - while(ros::ok()){ros::spinOnce();} - return 0; -} - -void arrayCallback(const std_msgs::UInt16MultiArray::ConstPtr& array){ - int i = 0; - for(std::vector::const_iterator it = array->data.begin(); it != array->data.end(); ++it){ - pwmVals[i] = *it; - i++; - } - char hexVals[32]; - string sinput1; //contains converted hex values - for (int i =0; i<8; i++){ - int valueOf = pwmVals[i]; - sinput1 = sinput1 + convertTo3BitHex(valueOf); - if(i<7){sinput1 = sinput1 + "~";} - } - cout << sinput1; - writeStream (file_i2c, sinput1); - char buf2[32]; - readStream(file_i2c, buf); - return; -} From 6a722d507c1dd7db4ed3c33819149ee7de20d928 Mon Sep 17 00:00:00 2001 From: Kyle <43458322+kyle-stevens@users.noreply.github.com> Date: Thu, 9 May 2019 15:14:51 -0700 Subject: [PATCH 12/16] Delete placeholder.txt --- robotside/src/placeholder.txt | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 robotside/src/placeholder.txt diff --git a/robotside/src/placeholder.txt b/robotside/src/placeholder.txt deleted file mode 100644 index cf529d7..0000000 --- a/robotside/src/placeholder.txt +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env python - From 1dc848f089d4b69e31de13c66a8ca2abdc03e3e2 Mon Sep 17 00:00:00 2001 From: Kyle <43458322+kyle-stevens@users.noreply.github.com> Date: Thu, 9 May 2019 15:14:58 -0700 Subject: [PATCH 13/16] Delete subber.cpp --- robotside/src/subber.cpp | 50 ---------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 robotside/src/subber.cpp diff --git a/robotside/src/subber.cpp b/robotside/src/subber.cpp deleted file mode 100644 index 56bac95..0000000 --- a/robotside/src/subber.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -#include -#include - -#include "ros/ros.h" - -#include "std_msgs/MultiArrayLayout.h" -#include "std_msgs/MultiArrayDimension.h" -#include "std_msgs/UInt16MultiArray.h" - -int Arr[8]; -void arrayCallback(const std_msgs::UInt16MultiArray::ConstPtr& array); - -int main(int argc, char **argv) -{ - - ros::init(argc, argv, "arraySubscriber"); - - ros::NodeHandle n; - - ros::Subscriber sub3 = n.subscribe("array", 1, arrayCallback); - while (ros::ok()) - { - ros::spinOnce(); - - for(int j = 1; j < 8; j++) - { - printf("%d, ", Arr[j]); - } - - printf("\n"); - - } - return 0; -} - -void arrayCallback(const std_msgs::UInt16MultiArray::ConstPtr& array) -{ - - int i = 0; - // print all the remaining numbers - for(std::vector::const_iterator it = array->data.begin(); it != array->data.end(); it++) - { - Arr[i] = *it; - i++; - } - - return; -} From e487a6f736bb88129a910e36554b31c0d372de29 Mon Sep 17 00:00:00 2001 From: Kyle <43458322+kyle-stevens@users.noreply.github.com> Date: Thu, 9 May 2019 15:15:06 -0700 Subject: [PATCH 14/16] Delete tester.cpp --- robotside/src/tester.cpp | 42 ---------------------------------------- 1 file changed, 42 deletions(-) delete mode 100644 robotside/src/tester.cpp diff --git a/robotside/src/tester.cpp b/robotside/src/tester.cpp deleted file mode 100644 index 01720ce..0000000 --- a/robotside/src/tester.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include - -#include "ros/ros.h" - -#include "std_msgs/MultiArrayLayout.h" -#include "std_msgs/MultiArrayDimension.h" - -#include "std_msgs/UInt16MultiArray.h" - -int main(int argc, char **argv) -{ - - - ros::init(argc, argv, "arrayPublisher"); - - ros::NodeHandle n; - - ros::Publisher pub = n.advertise("array", 1); - - while (ros::ok()) - { - std_msgs::UInt16MultiArray array; - //Clear array - array.data.clear(); - //for loop, pushing data in the size of the array - for (int i = 0; i < 8; i++) - { - //assign array a random number between 0 and 255. - array.data.push_back(rand() % 255); - } - //Publish array - pub.publish(array); - //Let the world know - ROS_INFO("I published something!"); - //Do this. - ros::spinOnce(); - //Added a delay so not to spam - sleep(2); - } - -} From 5cd863548b112992a203b2fe523ddb461361a6df Mon Sep 17 00:00:00 2001 From: Kyle <43458322+kyle-stevens@users.noreply.github.com> Date: Thu, 9 May 2019 15:16:05 -0700 Subject: [PATCH 15/16] final i2c hex conversion --- robotside/hexConverterv2.cpp | 134 +++++++++++++++++++++++++++++++++++ robotside/tester.cpp | 42 +++++++++++ 2 files changed, 176 insertions(+) create mode 100644 robotside/hexConverterv2.cpp create mode 100644 robotside/tester.cpp diff --git a/robotside/hexConverterv2.cpp b/robotside/hexConverterv2.cpp new file mode 100644 index 0000000..b3dea15 --- /dev/null +++ b/robotside/hexConverterv2.cpp @@ -0,0 +1,134 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + +using namespace std; + +int addr1 = 0x04; //primary address //successive i2c devices +int file_i2c; //primary address +int pwmVals[8]; +char *filename = (char*)"/dev/i2c-1"; +int i2c_slave_overflow = 32; + +void arrayCallback(const std_msgs::UInt16MultiArray::ConstPtr& array); + +bool writeStream(int file_i2c, string output) { + if (output.length() <= i2c_slave_overflow) { + if (write(file_i2c, output.c_str(), output.length()) != output.length()) { + printf("\tFailed to write to the i2c bus.\n"); + } + } + else { + printf("\t\tinput too long |:| overflow bounds exceeded and message voided\n"); + } + return true; +} + +bool readStream(int file_i2c, char buf[]) { + int n=32; //this should be the number of expected characters + if (read(file_i2c, buf, n) != n) { + printf("\ti2c read transaction |:| failed\n"); + } + else { + printf("\t%s\n", buf); + } +} + +string intToHexDig(int value) { + string cHex;//this block can be written as a case statement, but im lazy + if (value == 15) {cHex = 'f';} + else if (value == 14) {cHex = 'e';} + else if (value == 13) {cHex = 'd';} + else if (value == 12) {cHex = 'c';} + else if (value == 11) {cHex = 'b';} + else if (value == 10) {cHex = 'a';} + else if (value == 9) {cHex = '9';} + else if (value == 8) {cHex = '8';} + else if (value == 7) {cHex = '7';} + else if (value == 6) {cHex = '6';} + else if (value == 5) {cHex = '5';} + else if (value == 4) {cHex = '4';} + else if (value == 3) {cHex = '3';} + else if (value == 2) {cHex = '2';} + else if (value == 1) {cHex = '1';} + else if (value == 0) {cHex = '0';} + return cHex; +} + +string convertTo3BitHex(int decimal) { + string converted; + int firstChar = (int)(decimal/ (16 * 16)); + int firstRemainder = (int)(decimal % (16 * 16)); + int secondChar = (int)(firstRemainder / (16)); + int secondRemainder = (int)(firstRemainder % (16)); + int thirdChar = secondRemainder; + string cfirstChar, csecondChar, cthirdChar; + cfirstChar = intToHexDig(firstChar); + csecondChar = intToHexDig(secondChar); + cthirdChar = intToHexDig(thirdChar); + + converted = converted + cfirstChar; + converted = converted + csecondChar; + converted = converted + cthirdChar; +// cout << converted << endl; +// cout << "done"<::const_iterator it = array->data.begin(); it != array->data.end(); ++it){ + pwmVals[i] = *it; + i++; + } + cout << pwmVals < +#include + +#include "ros/ros.h" + +#include "std_msgs/MultiArrayLayout.h" +#include "std_msgs/MultiArrayDimension.h" + +#include "std_msgs/UInt16MultiArray.h" + +int main(int argc, char **argv) +{ + + + ros::init(argc, argv, "arrayPublisher"); + + ros::NodeHandle n; + + ros::Publisher pub = n.advertise("array", 1); + + while (ros::ok()) + { + std_msgs::UInt16MultiArray array; + //Clear array + array.data.clear(); + //for loop, pushing data in the size of the array + for (int i = 0; i < 8; i++) + { + //assign array a random number between 0 and 255. + array.data.push_back(rand() % 255); + } + //Publish array + pub.publish(array); + //Let the world know + ROS_INFO("I published something!"); + //Do this. + ros::spinOnce(); + //Added a delay so not to spam + sleep(2); + } + +} From c92571cdf9d4a53bc52ce5486387f4a338b60136 Mon Sep 17 00:00:00 2001 From: Kyle <43458322+kyle-stevens@users.noreply.github.com> Date: Fri, 24 May 2019 13:09:38 -0700 Subject: [PATCH 16/16] Create i2c setup readme --- robotside/i2c setup readme | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 robotside/i2c setup readme diff --git a/robotside/i2c setup readme b/robotside/i2c setup readme new file mode 100644 index 0000000..9413b83 --- /dev/null +++ b/robotside/i2c setup readme @@ -0,0 +1,31 @@ +STEP I: + sudo apt-get install libi2c-dev i2c-tools +STEP II: + sudo i2cdetect -y -r 1 + + should output... + 0 1 2 3 4 5 6 7 8 9 a b c d e f +00: — — — — — — — — — — — — — +10: — — — — — — — — — — — — — — — — +20: — — — — — — — — — — — — — — — — +30: — — — — — — — — — — — — — — — — +40: — — — — — — — — — — — — — — — — +50: — — — — — — — — — — — — — — — — +60: — — — — — — — — — — — — — — — — +70: — — — — — — — — + +STEP III: + connect the arduino to the nvidia with the provided arduino script and rerun + sudo i2cdetect -y -r 1 + + should now output + 0 1 2 3 4 5 6 7 8 9 a b c d e f +00: — — — 04 — — — — — — — — — +10: — — — — — — — — — — — — — — — — +20: — — — — — — — — — — — — — — — — +30: — — — — — — — — — — — — — — — — +40: — — — — — — — — — — — — — — — — +50: — — — — — — — — — — — — — — — — +60: — — — — — — — — — — — — — — — — +70: — — — — — — — — +