SunFounder GalaxyRVR Kit for Arduino, Release 1.0
(continued from previous page)
SoftPWMSet(in3, 0);
SoftPWMSet(in4, 255);
}
In this code, we set all motors to rotate clockwise. The rover will spin around its own axis and the direction will change
to the left.
For making the rover turn right, the concepts are the same but the directions are reversed. Can you figure out how to
do it?
Step 4: Moving in All Directions
As we develop more functionalities for our Mars Rover, our code could become quite long and messy. In programming,
it’s a good practice to keep your code organized and maintainable. One way to achieve this is by creating separate
functions for separate tasks.
In this case, we can create separate functions for each direction the rover can move. This not only makes our code
easier to understand but also allows us to re-use these functions anywhere in our program without having to re-write
the same lines of code.
Let’s see how we can do this:
With this structure, our main loop remains simple and easy to follow. We can clearly see that the rover moves forward,
then backward, then turns left and right, and finally stops.
The details of how each of these actions is achieved are hidden away in separate functions. This is a key aspect of good
programming practices known as abstraction.
Step 5: Sharing and Reflection
Congratulations on completing this exploration journey with the Mars Rover! This is a practical application of your
knowledge of science and engineering, and you did a fantastic job!
Now, you can share how your rover overcomes various terrain obstacles. You could film your rover navigating different
terrains, or show off your rover to your friends.
Reflecting on your learning process is also very important. What have you learned during this process? Did any new
ideas or creative thoughts emerge? What have you gained in controlling motors and programming?
You can continue to explore, discover new knowledge, and constantly improve yourself. Keep it up, future scientists
and engineers!
3.6 Lesson 6: Exploring the Obstacle Avoidance Module
We’re diving into the world of the Infrared Obstacle Avoidance Module. Tucked at the sides of our Mars Rover, these
sensors act as the rover’s “eyes,” helping it dodge side obstacles and safely navigate the Martian landscape.
We’ll learn how to integrate these modules with our rover, unravel the magic behind their functioning, and develop
code to make our rover smartly sidestep any hurdles it comes across.
Get ready to gear up our rover with some Martian obstacle-dodging intelligence! Let’s get rolling!
Note: If you are learning this course after fully assembling the GalaxyRVR, you need to move this switch to the right
before uploading the code.
50 Chapter 3. Course Mode