Previous raspcatbot was just too fast for reliable joystick control.
So I replaced the 1500rpm gear motors with original 330rpm motors on my 2nd T101 platform.
The new design with just one lipo is much smaller, until now 3S 1000mAh 25C lipo.
But ordered 4S 1300mAh 95C lipos just arrived
I want the robot to be able to drive outside, so I had to get rid of home router dependency.
While it was easy to make the ESP32 an AP, it is not easy to determine the devices only connected to it.
Making the Raspberry Pi (ZeroW now) AP is not that easy either.
So I took the easiest solution and made my Android smartphone the access point.
Pi program dead-man_button.c needs to be started, no problem using JuiceSSH app on the smartphone.
Even changes to C code and compilation can be done that way, even when outside:
I did record a first video with now fully functional Wifi joystick on target ground, hardplates I already used for preparation of another robot (Asuro) for 2007 Vienna RobotChallenge. Plates and courses for different challenges can be found here (google translated from German):
https://stamm-wilbrandt.de/RobotChallenge/
This is the new Wifi joystick raspcatbot video:
https://www.youtube.com/watch?v=sqHJmhtsR-M
And here is the code, in order to be prepared for corrections/enhancements as gists.
This is Pi dead-man_button.c (no need for netcat anymore, TCP server code now included):
https://gist.github.com/Hermann-SW/b489 ... 10c8d00ae7
This is dead-man helper code. Sometimes an emergency stop caused by heartbeat loss does not correctly cleanup. Then port 1337 is blocked for 1 minute in FIN_WAIT2 state. This helper code starts dead-man_button on port 1318 in that case:
https://gist.github.com/Hermann-SW/042b ... 22fe2a8d5f
Code: Select all
#!/bin/bash
while true
do
fin_wait2=`netstat 2>/dev/null | grep 1337`
if [[ "$fin_wait2" = "" ]]
then
sudo ./dead-man_button
else
sudo ./dead-man_button 1338
fi
done
Finally this is wifi_joystick.ino sketch. Now connects to either 1337 or 1338 port. Split for forward/backward is now done at 112 (the joystick default position value). I had no idea how to use two axis of joystick to control two motors of caterpillar robot. Did try the easiest thing, and that was a good choice. Control one motor by one axis, the other motor by the other. Both axis maximal is full speed forward, both axix 0 is full speed backward. one axis 255 and the other 0 is full speed center point rotation (clockwise or anticlockwise). And you can use any setting else, so small changes in direction can be easily done. Anyway it is not that easy to control the robot with it as you can see in the video, I hope it will get better with more handson:
https://gist.github.com/Hermann-SW/afeb ... 57e7048f87
Code: Select all
...
while (1)
{
// fprintf(stderr, ".");
struct timeval timeout1={.tv_sec=0, .tv_usec=500000};
if (select(nfd + 1, &set, NULL, NULL, &timeout1) <= 0) emergency_stop(1);
if (read(nfd, buf, 1 ) < 1) emergency_stop(2);
struct timeval timeout2={.tv_sec=0, .tv_usec=500000};
if (select(nfd + 1, &set, NULL, NULL, &timeout2) <= 0) emergency_stop(3);
if (read(nfd, buf+4, 1 ) < 1) emergency_stop(4);
gpioWrite(gpioLeftFwd, buf[4] >= 112);
gpioWrite(gpioLeftRew, buf[4] < 112);
gpioWrite(gpioRghtFwd, buf[0] >= 112);
gpioWrite(gpioRghtRew, buf[0] < 112);
gpioPWM(gpioLeftPwm, (buf[4] < 112) ? 255-(255/112.0)*buf[4] : (255/143.0)*buf[4]-255);
gpioPWM(gpioRghtPwm, (buf[0] < 112) ? 255-(255/112.0)*buf[0] : (255/143.0)*buf[0]-255);
}
...