


Advanced Guide to RohLang Programming
​
Welcome to the advanced tutorial for RohLang, where we will explore the advanced programming capabilities of the Rohbot Kit. This guide is intended for those who are familiar with the basics of RohLang and wish to explore its more complex functionalities.
​
Advanced Commands and Syntax
1. Parameterized Commands:
- RohLang allows the use of parameters with commands for more precise control. For example, `F 3 50` could mean "move forward for 3 seconds at 50% speed."
2. Sensor Integration:
- Utilize sensor data in your commands. For example, `IF IR_SENSOR < 20 THEN F 2` commands the robot to move forward if the infrared sensor reading is less than 20.
​
Complex Movement Patterns
Let's create a program that makes the robot follow a more complex pattern, like an '8' figure.
// Move in figure 8
LOOP 2
F 2 // Move forward
R 45 // Turn slightly right
F 3 // Move forward in curve
R 90 // Sharper right turn
F 3 // Complete the loop part of 8
R 45 // Align to start next loop
ENDLOOP
S // Stop after completing figure 8
Working with Functions
Functions in RohLang allow you to encapsulate a set of commands and reuse them.
// Define a function for a zigzag pattern
FUNCTION zigzag
F 2 // Move forward
R 45 // Turn right 45 degrees
F 2 // Move forward
L 45 // Turn left 45 degrees
ENDFUNCTION
// Call zigzag function twice
CALL zigzag
CALL zigzag
Advanced Sensor-Based Decision Making
Utilize sensor data for dynamic decision-making. For instance, create a wall-following robot:
WHILE true
IF LEFT_DIST_SENSOR < 10
// Too close to the wall on the left
R 10 // Slightly turn right
ELSEIF RIGHT_DIST_SENSOR < 10
// Too close to the wall on the right
L 10 // Slightly turn left
ELSE
F 1 // Otherwise, move forward
ENDIF
ENDWHILE
Implementing Algorithms
RohLang can implement simple algorithms. For example, a basic search algorithm to find and approach a target:
FOUND = false
WHILE NOT FOUND
IF CAMERA_DETECTS_TARGET
F 1 // Move towards the target
IF TARGET_WITHIN_REACH
FOUND = true
PICK_TARGET // Custom command to pick the target
ENDIF
ELSE
R 15 // Rotate to search for the target
ENDIF
ENDWHILE
Debugging and Optimization
- Debugging: Regularly test your code and use debugging techniques, such as printing sensor readings to the console, to troubleshoot issues.
- Optimization: Refine your code for efficiency. For instance, avoid unnecessary repetitions and optimize sensor usage.
​
Expanding RohLang’s Capabilities
- Community Contributions: As an open-source language, RohLang encourages contributions. Share your custom functions and improvements with the community.
- Interfacing with Additional Modules: Explore interfacing RohLang with additional modules or sensors to expand its capabilities.
​
Conclusion
This advanced guide offers a deeper insight into RohLang’s potential for complex programming tasks, enabling users to create sophisticated programs for their Rohbot Kit. Experimentation and continual learning are key to mastering these advanced concepts.