Sunday, April 30, 2017

Day 15

Topics

  1. RC cars transistor control
  2. Passing pointers to functions

RC cars transistor control
   Moving along, I tried to tackle this problem using a more intuitive understanding of the components. I forced myself to rewrite the code without looking back at examples from previous labs. I had noticed a tendency to copy bits and pieces from previous labs, something I feel was hampering my education. Not including the parallel branch with the capacitor, diode, and motor (which was new), I added components to the board by first explaining to myself what the part would do. This intuitive approach also guided my code. I know what a transistor works now so I worked through the logic of what I would need to connect and apply a voltage at the gate. The pot was on it's own little island and used to grab values.




   I had the code written and thought I should have worked. Alas, my motor would spin at a generally constant speed regardless of what I was doing. After some debugging I realized it was probably a component. I completely disconnected the base of the transistor and (BINGO) the wheels still spun. Edgar gave me a new transistor and that solved my problem.





Passing pointers to functions

   Finally we have landed on the part of pointers that seems interesting and useful. While we had been spending time working out the logic of how pointers work, Now we have a way to write functions that don't need to assume we have the correct variable declared because we can use pointers in the function and direct them to the arguments of the function. 
   The first modification required of us was to take in the threshold values from the user and check them for consistency with the program. I made a function and feed in pointer arguments. 


    I declared the variable and called the function. It worked. My problem came with opening the file which was to be read. I created the file, placed it in the same folder as my program, and reread the entire section on using files. Nothing appeared to be wrong with the code or the way the files was named or started.

 



   Soldiering on, I made the second modification, which was rather simple. Adding a variable, NumEvents, and setting it to zero, then incrementing NumEvents inside the if loop where an event is detected. Lastly, I print the value of the NumEvents once the file has been closed.









   Although I am unable to to check this part of the code because of the file problem, I don't anticipate any problem with this simple modification. 

Tuesday, April 18, 2017

Day 11

Topic's

  • Lecture Notes
  • Serial Lab
  • File programming
Lecture Notes

   I wrote a simple hello world program.

I did a little bit a research into pointers and found a way to print out the memory location of our variables.
 


Serial Lab
   As expected, the serial monitor printed out a reading every second.
   





   I had some trouble with my syntax but Edgar showed that I was using the wrong write to control statement for the servo. I had been using analog write when I should have been using motorname.write.










File Programming

   I allow the user to enter in data.


   You can also see the file being setup in that previous picture. This is the part of my program to calculate the values I want.




  The max values happens here.




   This part will make sure you didn't try to end before you started. At the same time, this restricts the time interval to 48 hours. 


      After that, I got the data printed to a text file. 




Day 10

Topics

  •  IR sweeper
  • Statistical Models



IR Sweeper


   I got rid of the portions about the LED that were in the lab example. What remained was the function that read distance which I passed my increment and then made a simple test of the max value. The reason I can only sweep to 150 is because I kept running into problems when I would span the full 180 degrees. For some strange reason, the max distance would always set itself onto those outer 30 degrees. When I did limit my scope the problem solved itself. I am not exactly sure why this was happening. I think it might be the way the sweeper is pulling on the wires at that range. Either way, I have to call it after a certain time dumped into solving that problem. 




Statistical Models

   I am still baffled as to how to finish the the variance and standard deviation parts for the last two.

Cyptography

   I am still trying to find the way to do this. I have the feeling that it will require shifting my character array along the ascii table. I have some code and some pseudocode but I can not quite figure it out. First, I will sit between the lowercase parts.



 


   I can't really go onto the second part because I don't know how to do this whole casting section.

Day 6

Topics

  • Modulating programs
  • Programming and calling a modular function
  • Using a photoresistor and a button

Programming

   The first step was to make a program with a the defined prototype statement.



   I had to also declare the prototype in order to be able to use the function.

   Next, I was to use the function written while calculating. I looked at the function that was there and realized I would be smart to take out rho and use it as a definition instead of a local variable in the distance function.



   I realize now I would be best to tear the entire thing apart and have each step as a function. I would also need to define some new variables. At least, I had designed this program, I would use this way.



   While I would like to do this, I think I will instead convert the original program and use that. I don't need to phi or theta values anywhere else that in the function.



   With this declaration as well as the function for calculating the angle between two points, I can then return the values I want simply.




   To add the ability for the user to input the cardinal direction, I first added Two arguments to the conversion function as well declaring a new set of variables to the main.


   I actually realized that I didn't need to declare the character as an array because it only has the one element. I made that change and then updated by function.




   If I am to add the ability to change the West-East direction as well then I had best pull out the whole phi phi theta parts. After all of the conversions are done then I put the actual conversion. This made the program a little more readable and smaller. Of course, this same structure is repeated for both points.






That combines the entire program modifications into a set of functions.

Wednesday, April 5, 2017

Day 9

Topics

  • Class Notes
  • Servo Lab
  • Array Homework
Lecture Notes

   We presented out project which worked except for the errors we forced onto ourselves when we were going over the project with Professor Mason. We have to remember to shut up when we are ahead and not invite loses. Next time I will have to spend a little more time really getting the code to run well and remove the things that didn't work from the final project. 


   Working with arrays, the concept isn't overly difficult just plenty of nuance I'll have to mess with. The next step is to integrate the ability to access files from my computer to populate the array. This entire topic smells like rocket payload to me, data aquisition and manipulation. 

Servo Lab

   We started off the class with our first step into working with servos.   Robert and I quickly got ours working.
 

   I used the original code to find the values I need to pass my servo in order for it to move the right amount. It turns out the original code had mapped val to be a one to one translation into angles of
 movement from about 0 to 180 degrees. 





   
   It was easy enough to set up a digital read with my IR sensor and use that to trigger the servo. Than all I had to do was to write a simple if statement and pass my servo the correct values I needed. 


Array Homework

   The first problem was a matter of printing out the values after compiling a program. I run one code, commend out the appropriate parts, recompile, and run the code a second time. The first value is 14  and the second value is 6.



Then I moved onto the random number function. I tried to get the function to work as is but I kept running into the problem of data types. The rand() is an integer and, for some reason, the compiler didn't like that I used doubles in my interval start and interval end. It wasn't until I changed those to integers did the function actually work. I am sure this is a compiler problem because the book says that this will usually result in the lower data type being automatically converted to higher data type and then working.


   The same thing happened with my array. I initially defined it to be a double with didn't store values because i was feeding it integers. When I redefined the array then it worked. 

Mean and Variance Programming

   The first step was to write a function that returns a random value.



   I then wrote a program that would populate an array with the elements of my random numbers. 


   I then found the mean of my array



   next I wrote a bit of code to find the valence in my sample. 



   My theoretical mean is 7 and my theoretical variance is 3. When I ran my program with a 14 data points, these are my results