Skip to main content

Type-Driven Cross-Programming for Android and LEGO Mindstorms Interoperability

  • Conference paper
  • First Online:
  • 784 Accesses

Part of the book series: Lecture Notes in Computer Science ((LNISA,volume 11703))

Abstract

We present Legodroid, a Java library for Android that allows cross-programming LEGO Mindstorms through an Android device to exploit its extra computational capabilities in a seamless way. From a programmer’s perspective, the paradigm it suggests for programming the EV3 is straightforward and resembles a standard main function in the likes of leJOS, which natively runs on the EV3 side though. Moreover, the library imposes type-driven coding patterns for interacting with motors and sensors, which guide developers in writing correct code with less runtime errors thanks to a rigid discipline over types. This is particularly effective in Android, whose component-based pattern complicates coding of traditional long-running algorithms for robots. Compared to leJOS, Legodroid users reported shorter bugfixing times and a more accessible paradigm for programming the robot, which had a positive impact on how much resources could be put in writing smarter algorithms and sophisticate interactions.

This is a preview of subscription content, log in via an institution.

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Notes

  1. 1.

    At the time of writing, Legodroid does not support wifi connections, as the bluetooth counterpart is preferable in most cases. A WifiConnection class is expected by design though and will be added in a future update.

  2. 2.

    The EV3 CPU is a 300 MHz TI Sitara AM1808 (ARM926EJ-S Core) with 64 MB of RAM.

  3. 3.

    We refer to the EV3.Api nested static class as Api for brevity.

  4. 4.

    The functional interface \(\texttt {Callable<T>}\) represents functions with no arguments and a result of type \(\texttt {T}\), in the same way as \(\texttt {Supplier<T>}\) does, whose functional type can be written as \(\varnothing \rightarrow \texttt {T}\).

  5. 5.

    Refer to the documentation of EV3 firmware instructions (op-codes opOutput_ Polarity and opOutput_Set_Type) in section 4.9 of [37].

  6. 6.

    In Java 8+ all the mentioned language constructs are equivalent type-wise.

  7. 7.

    Bachelor degree in Computer Science, year 2018-19, at DAIS, Università Ca’ Foscari Venezia.

References

  1. Barendregt, H.P.: Functional programming and lambda calculus. In: Formal Models and Semantics, pp. 321–363. Elsevier (1990)

    Google Scholar 

  2. Bloch, J.: Effective Java. Pearson Education India (2016)

    Google Scholar 

  3. Bracha, G.: Generics in the Java Programming Language (2004)

    Google Scholar 

  4. Bracha, G., Odersky, M., Stoutamire, D., Wadler, P.: Making the future safe for the past: adding genericity to the Java programming language. ACM SIGPLAN Not. 33(10), 183–200 (1998)

    Article  Google Scholar 

  5. Brady, E.: Programming and reasoning with algebraic effects and dependent types. ACM SIGPLAN Not. 48, 133–144 (2013)

    Article  Google Scholar 

  6. Brady, E.: Type-Driven Development with Idris. Manning (2016)

    Google Scholar 

  7. Cardelli, L.: Typeful programming. In: Formal Description of Programming Concepts, pp. 431–507 (1991)

    Google Scholar 

  8. Chalin, P., James, P.R.: Non-null references by default in Java: alleviating the nullity annotation burden. In: Ernst, E. (ed.) ECOOP 2007. LNCS, vol. 4609, pp. 227–247. Springer, Heidelberg (2007). https://doi.org/10.1007/978-3-540-73589-2_12

    Chapter  Google Scholar 

  9. Chalin, P., James, P.R., Rioux, F.: Reducing the use of nullable types through non-null by default and monotonic non-null. IET Softw. 2(6), 515–531 (2008)

    Article  Google Scholar 

  10. Damas, L., Milner, R.: Principal type-schemes for functional programs. POPL 82, 207–212 (1982)

    Google Scholar 

  11. Ehringer, D.: The Dalvik virtual machine architecture. Tech. Rep. 4(8) (2010)

    Google Scholar 

  12. Ellis, B., Stylos, J., Myers, B.: The factory pattern in API design: a usability evaluation. In: Proceedings of the 29th International Conference on Software Engineering, pp. 302–312. IEEE Computer Society (2007)

    Google Scholar 

  13. Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design patterns: abstraction and reuse of object-oriented design. In: Nierstrasz, O.M. (ed.) ECOOP 1993. LNCS, vol. 707, pp. 406–431. Springer, Heidelberg (1993). https://doi.org/10.1007/3-540-47910-4_21

    Chapter  Google Scholar 

  14. Gibbons, J.: Design patterns as higher-order datatype-generic programs. In: Proceedings of the 2006 ACM SIGPLAN Workshop on Generic Programming, pp. 1–12. ACM (2006)

    Google Scholar 

  15. Goetz, B.: State of the Lambda, 4th edn. (2011). http://cr.openjdk.java.net/~briangoetz/lambda/lambda-state-4.html

  16. Google Inc.: Android Executor Interface Documentation (2012). https://developer.android.com/reference/java/util/concurrent/Executor

  17. Google Inc.: Android FutureTask Class Documentation (2012). https://developer.android.com/reference/java/util/concurrent/FutureTask

  18. Google Inc.: Understand the Activity Lifecycle (Android documentation) (2014). https://developer.android.com/guide/components/activities/activity-lifecycle

  19. Google Inc.: Android Studio download page (2019). https://developer.android.com/studio/

  20. Haack, C., Poll, E.: Type-based object immutability with flexible initialization. In: Drossopoulou, S. (ed.) ECOOP 2009. LNCS, vol. 5653, pp. 520–545. Springer, Heidelberg (2009). https://doi.org/10.1007/978-3-642-03013-0_24

    Chapter  Google Scholar 

  21. Haller, P., Prokopec, A., Miller, H., Klang, V., Kuhn, R., Jovanovic, V.: Futures and promises (2012). http://docs.scala-lang.org/overviews/core/futures.html

  22. Kestelyn, J.: How Apache Spark, Scala, and Functional Programming Made Hard Problems Easy at Barclays (2015). https://blog.cloudera.com/blog/2015/08/

  23. McClean, J.: Lambdas are not functional programming (2018). https://medium.com/@johnmcclean/lambdas-are-not-functional-programming-63533ce2eb74

  24. Mycroft, A.: Polymorphic type schemes and recursive definitions. In: Paul, M., Robinet, B. (eds.) Programming 1984. LNCS, vol. 167, pp. 217–228. Springer, Heidelberg (1984). https://doi.org/10.1007/3-540-12925-1_41

    Chapter  Google Scholar 

  25. Nguyen, D., Wong, S.B.: Design patterns for lazy evaluation. ACM SIGCSE Bull. 32, 21–25 (2000)

    Article  Google Scholar 

  26. Odersky, M., Wadler, P.: Pizza into Java: translating theory into practice. In: POPL (1997)

    Google Scholar 

  27. Oracle Corp: JDK 8 Documentation: Package java.util.function (2010). https://docs.oracle.com/javase/8/docs/api/java/util/function/package-summary.html

  28. Oracle Corp: Method References (Java Documentation) (2017). https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html

  29. Petricek, T.: Type-First Development (2015). http://tomasp.net/blog/type-first-development.aspx/

  30. Pratikakis, P., Spacco, J., Hicks, M.: Transparent proxies for java futures. In: Proceedings of the 19th Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications, OOPSLA 2004, pp. 206–223. ACM, New York (2004)

    Google Scholar 

  31. Seemann, M.: Type Driven Development (2015). https://blog.ploeh.dk/2015/08/10/type-driven-development/

  32. Seemann, M.: Type Driven Development (2015). https://blog.ploeh.dk/2016/02/10/types-properties-software/

  33. Setzer, A.: Java as a functional programming language. In: Geuvers, H., Wiedijk, F. (eds.) TYPES 2002. LNCS, vol. 2646, pp. 279–298. Springer, Heidelberg (2003). https://doi.org/10.1007/3-540-39185-1_16

    Chapter  Google Scholar 

  34. Subramaniam, V.: Functional programming in Java: harnessing the power of Java 8 Lambda expressions. In: Pragmatic Bookshelf (2014)

    Google Scholar 

  35. The Lego Group: LEGO Mindstorms NXT Education Kit (2011). https://www.generationrobots.com/media/Lego-Mindstorms-NXT-Education-Kit.pdf

  36. The Lego Group: EV3 Communication Developer Kit (2013). https://le-www-live-s.legocdn.com/sc/media/files/ev3-developer-kit/lego

  37. The Lego Group: EV3 Firmware Developer Kit (2013). https://le-www-live-s.legocdn.com/sc/media/files/ev3-developer-kit/lego

  38. The Lego Group: ROBOLAB Reference Guide (2013). http://www.legoengineering.com/robolab-programming-references/

  39. Warburton, R.: Java 8 Lambdas: Pragmatic Functional Programming. O’Reilly Media Inc., Sebastopol (2014)

    Google Scholar 

  40. Welc, A., Jagannathan, S., Hosking, A.: Safe futures for Java. In: Proceedings of the 20th Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications, OOPSLA 2005, pp. 439–453. ACM, New York (2005)

    Google Scholar 

  41. Wlaschin, S.: Designing with Types (2013). https://fsharpforfunandprofit.com/series/designing-with-types.html

  42. Wlaschin, S.: Designing with Types: Making illegal states unrepresentable (2013). https://fsharpforfunandprofit.com/posts/designing-with-types-making-illegal-states-unrepresentable

  43. Xi, H., Pfenning, F.: Dependent types in practical programming. In: Proceedings of the 26th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 214–227. ACM (1999)

    Google Scholar 

  44. Zhang, L., Krintz, C., Nagpurkar, P.: Language and virtual machine support for efficient fine-grained futures in Java. In: Proceedings of the 16th International Conference on Parallel Architecture and Compilation Techniques, PACT 2007, pp. 130–139. IEEE Computer Society, Washington, DC (2007)

    Google Scholar 

  45. Zhang, L., Krintz, C., Soman, S.: Efficient support of fine-grained futures in Java. In: International Conference on Parallel and Distributed Computing Systems (PDCS). Citeseer (2006)

    Google Scholar 

  46. Zibin, Y., Potanin, A., Ali, M., Artzi, S., et al.: Object and reference immutability using java generics. In: Proceedings of the 6th Joint Meeting of the European Software Engineering Conference and the ACM SIGSOFT Symposium on the Foundations of Software Engineering, pp. 75–84. ACM (2007)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Alvise Spanò .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2019 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Spanò, A., Cortesi, A., Zausa, G. (2019). Type-Driven Cross-Programming for Android and LEGO Mindstorms Interoperability. In: Saeed, K., Chaki, R., Janev, V. (eds) Computer Information Systems and Industrial Management. CISIM 2019. Lecture Notes in Computer Science(), vol 11703. Springer, Cham. https://doi.org/10.1007/978-3-030-28957-7_17

Download citation

  • DOI: https://doi.org/10.1007/978-3-030-28957-7_17

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-28956-0

  • Online ISBN: 978-3-030-28957-7

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics